41a6c3
diff --git a/modules/http/http_request.c b/modules/http/http_request.c
41a6c3
index cdfec8b..c97dc77 100644
41a6c3
--- a/modules/http/http_request.c
41a6c3
+++ b/modules/http/http_request.c
41a6c3
@@ -73,19 +73,22 @@ static void update_r_in_filters(ap_filter_t *f,
41a6c3
     }
41a6c3
 }
41a6c3
 
41a6c3
-AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
+static void ap_die_r(int type, request_rec *r, int recursive_error)
41a6c3
 {
41a6c3
-    int error_index = ap_index_of_response(type);
41a6c3
-    char *custom_response = ap_response_code_string(r, error_index);
41a6c3
-    int recursive_error = 0;
41a6c3
+    char *custom_response;
41a6c3
     request_rec *r_1st_err = r;
41a6c3
 
41a6c3
-    if (type == AP_FILTER_ERROR) {
41a6c3
+    if (type == OK || type == DONE){
41a6c3
+        ap_finalize_request_protocol(r);
41a6c3
+        return;
41a6c3
+    }
41a6c3
+
41a6c3
+    if (!ap_is_HTTP_VALID_RESPONSE(type)) {
41a6c3
         ap_filter_t *next;
41a6c3
 
41a6c3
         /*
41a6c3
          * Check if we still have the ap_http_header_filter in place. If
41a6c3
-         * this is the case we should not ignore AP_FILTER_ERROR here because
41a6c3
+         * this is the case we should not ignore the error here because
41a6c3
          * it means that we have not sent any response at all and never
41a6c3
          * will. This is bad. Sent an internal server error instead.
41a6c3
          */
41a6c3
@@ -99,8 +102,14 @@ AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
          * next->frec == ap_http_header_filter
41a6c3
          */
41a6c3
         if (next) {
41a6c3
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01579)
41a6c3
-                          "Custom error page caused AP_FILTER_ERROR");
41a6c3
+            if (type != AP_FILTER_ERROR) {
41a6c3
+                ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01579)
41a6c3
+                              "Invalid response status %i", type);
41a6c3
+            }
41a6c3
+            else {
41a6c3
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02831)
41a6c3
+                              "Response from AP_FILTER_ERROR");
41a6c3
+            }
41a6c3
             type = HTTP_INTERNAL_SERVER_ERROR;
41a6c3
         }
41a6c3
         else {
41a6c3
@@ -108,20 +117,13 @@ AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
         }
41a6c3
     }
41a6c3
 
41a6c3
-    if (type == DONE) {
41a6c3
-        ap_finalize_request_protocol(r);
41a6c3
-        return;
41a6c3
-    }
41a6c3
-
41a6c3
     /*
41a6c3
      * The following takes care of Apache redirects to custom response URLs
41a6c3
      * Note that if we are already dealing with the response to some other
41a6c3
      * error condition, we just report on the original error, and give up on
41a6c3
      * any attempt to handle the other thing "intelligently"...
41a6c3
      */
41a6c3
-    if (r->status != HTTP_OK) {
41a6c3
-        recursive_error = type;
41a6c3
-
41a6c3
+    if (recursive_error != HTTP_OK) {
41a6c3
         while (r_1st_err->prev && (r_1st_err->prev->status != HTTP_OK))
41a6c3
             r_1st_err = r_1st_err->prev;  /* Get back to original error */
41a6c3
 
41a6c3
@@ -140,6 +142,10 @@ AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
         }
41a6c3
 
41a6c3
         custom_response = NULL; /* Do NOT retry the custom thing! */
41a6c3
+    } else {
41a6c3
+        int error_index = ap_index_of_response(type);
41a6c3
+        custom_response = ap_response_code_string(r, error_index);
41a6c3
+        recursive_error = 0;
41a6c3
     }
41a6c3
 
41a6c3
     r->status = type;
41a6c3
@@ -216,6 +222,11 @@ AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
     ap_send_error_response(r_1st_err, recursive_error);
41a6c3
 }
41a6c3
 
41a6c3
+AP_DECLARE(void) ap_die(int type, request_rec *r)
41a6c3
+{
41a6c3
+    ap_die_r(type, r, r->status);
41a6c3
+}
41a6c3
+
41a6c3
 static void check_pipeline(conn_rec *c)
41a6c3
 {
41a6c3
     if (c->keepalive != AP_CONN_CLOSE) {
41a6c3
@@ -337,18 +348,7 @@ void ap_process_async_request(request_rec *r)
41a6c3
     apr_thread_mutex_unlock(r->invoke_mtx);
41a6c3
 #endif
41a6c3
 
41a6c3
-    if (access_status == DONE) {
41a6c3
-        /* e.g., something not in storage like TRACE */
41a6c3
-        access_status = OK;
41a6c3
-    }
41a6c3
-
41a6c3
-    if (access_status == OK) {
41a6c3
-        ap_finalize_request_protocol(r);
41a6c3
-    }
41a6c3
-    else {
41a6c3
-        r->status = HTTP_OK;
41a6c3
-        ap_die(access_status, r);
41a6c3
-    }
41a6c3
+    ap_die_r(access_status, r, HTTP_OK);
41a6c3
 
41a6c3
     ap_process_request_after_handler(r);
41a6c3
 }
41a6c3
@@ -631,8 +631,8 @@ AP_DECLARE(void) ap_internal_fast_redirect(request_rec *rr, request_rec *r)
41a6c3
 
41a6c3
 AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r)
41a6c3
 {
41a6c3
-    request_rec *new = internal_internal_redirect(new_uri, r);
41a6c3
     int access_status;
41a6c3
+    request_rec *new = internal_internal_redirect(new_uri, r);
41a6c3
 
41a6c3
     AP_INTERNAL_REDIRECT(r->uri, new_uri);
41a6c3
 
41a6c3
@@ -648,12 +648,7 @@ AP_DECLARE(void) ap_internal_redirect(const char *new_uri, request_rec *r)
41a6c3
             access_status = ap_invoke_handler(new);
41a6c3
         }
41a6c3
     }
41a6c3
-    if (access_status == OK) {
41a6c3
-        ap_finalize_request_protocol(new);
41a6c3
-    }
41a6c3
-    else {
41a6c3
-        ap_die(access_status, new);
41a6c3
-    }
41a6c3
+    ap_die(access_status, new);
41a6c3
 }
41a6c3
 
41a6c3
 /* This function is designed for things like actions or CGI scripts, when
41a6c3
@@ -674,15 +669,9 @@ AP_DECLARE(void) ap_internal_redirect_handler(const char *new_uri, request_rec *
41a6c3
         ap_set_content_type(new, r->content_type);
41a6c3
     access_status = ap_process_request_internal(new);
41a6c3
     if (access_status == OK) {
41a6c3
-        if ((access_status = ap_invoke_handler(new)) != 0) {
41a6c3
-            ap_die(access_status, new);
41a6c3
-            return;
41a6c3
-        }
41a6c3
-        ap_finalize_request_protocol(new);
41a6c3
-    }
41a6c3
-    else {
41a6c3
-        ap_die(access_status, new);
41a6c3
+        access_status = ap_invoke_handler(new);
41a6c3
     }
41a6c3
+    ap_die(access_status, new);
41a6c3
 }
41a6c3
 
41a6c3
 AP_DECLARE(void) ap_allow_methods(request_rec *r, int reset, ...)