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