Commit b9bf3203 authored by Jim Jagielski's avatar Jim Jagielski
Browse files

Morph the ap_http_broken_backend_filter() proxy "specific"

filter to a generic http error handling output filter.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@358022 13f79535-47bb-0310-9956-ffa450edef68
parent bee8d112
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@
AP_DECLARE_DATA ap_filter_rec_t *ap_http_input_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_http_input_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_http_header_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_http_header_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_chunk_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_chunk_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_broken_backend_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_http_outerror_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_byterange_filter_handle;
AP_DECLARE_DATA ap_filter_rec_t *ap_byterange_filter_handle;


static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy,
static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy,
@@ -208,6 +208,8 @@ static int http_create_request(request_rec *r)
                                    NULL, r, r->connection);
                                    NULL, r, r->connection);
        ap_add_output_filter_handle(ap_http_header_filter_handle,
        ap_add_output_filter_handle(ap_http_header_filter_handle,
                                    NULL, r, r->connection);
                                    NULL, r, r->connection);
        ap_add_output_filter_handle(ap_http_outerror_filter_handle,
                                    NULL, r, r->connection);
    }
    }


    return OK;
    return OK;
@@ -243,9 +245,8 @@ static void register_hooks(apr_pool_t *p)
    ap_chunk_filter_handle =
    ap_chunk_filter_handle =
        ap_register_output_filter("CHUNK", ap_http_chunk_filter,
        ap_register_output_filter("CHUNK", ap_http_chunk_filter,
                                  NULL, AP_FTYPE_TRANSCODE);
                                  NULL, AP_FTYPE_TRANSCODE);
    ap_broken_backend_filter_handle =
    ap_http_outerror_filter_handle =
        ap_register_output_filter("BROKEN_BACKEND",
        ap_register_output_filter("HTTP_OUTERROR", ap_http_outerror_filter,
                                  ap_http_broken_backend_filter,
                                  NULL, AP_FTYPE_PROTOCOL);
                                  NULL, AP_FTYPE_PROTOCOL);
    ap_byterange_filter_handle =
    ap_byterange_filter_handle =
        ap_register_output_filter("BYTERANGE", ap_byterange_filter,
        ap_register_output_filter("BYTERANGE", ap_byterange_filter,
+12 −9
Original line number Original line Diff line number Diff line
@@ -1055,9 +1055,6 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_header_filter(ap_filter_t *f,
         */
         */
        ap_add_output_filter("CHUNK", NULL, r, r->connection);
        ap_add_output_filter("CHUNK", NULL, r, r->connection);
    }
    }
    /* If we have a Proxy request, add the BROKEN_BACKEND filter now */
    if (r->proxyreq != PROXYREQ_NONE)
        ap_add_output_filter("BROKEN_BACKEND", NULL, r, r->connection);


    /* Don't remove this filter until after we have added the CHUNK filter.
    /* Don't remove this filter until after we have added the CHUNK filter.
     * Otherwise, f->next won't be the CHUNK filter and thus the first
     * Otherwise, f->next won't be the CHUNK filter and thus the first
@@ -1333,7 +1330,8 @@ AP_DECLARE(long) ap_get_client_block(request_rec *r, char *buffer,
    return bufsiz;
    return bufsiz;
}
}


apr_status_t ap_http_broken_backend_filter(ap_filter_t *f,
/* Filter to handle any error buckets on output */
apr_status_t ap_http_outerror_filter(ap_filter_t *f,
                                     apr_bucket_brigade *b)
                                     apr_bucket_brigade *b)
{
{
    request_rec *r = f->r;
    request_rec *r = f->r;
@@ -1343,12 +1341,17 @@ apr_status_t ap_http_broken_backend_filter(ap_filter_t *f,
         e != APR_BRIGADE_SENTINEL(b);
         e != APR_BRIGADE_SENTINEL(b);
         e = APR_BUCKET_NEXT(e))
         e = APR_BUCKET_NEXT(e))
    {
    {
        if (AP_BUCKET_IS_ERROR(e)
        if (AP_BUCKET_IS_ERROR(e)) {
            && (((ap_bucket_error *)(e->data))->status == HTTP_BAD_GATEWAY)) {
            /*
             * Start of error handling state tree. Just one condition
             * right now :)
             */
            if (((ap_bucket_error *)(e->data))->status == HTTP_BAD_GATEWAY) {
                /* stream aborted and we have not ended it yet */
                /* stream aborted and we have not ended it yet */
                r->connection->keepalive = AP_CONN_CLOSE;
                r->connection->keepalive = AP_CONN_CLOSE;
            }
            }
        }
        }
    }


    return ap_pass_brigade(f->next,  b);
    return ap_pass_brigade(f->next,  b);
}
}
+4 −4
Original line number Original line Diff line number Diff line
@@ -42,7 +42,7 @@ extern "C" {
extern AP_DECLARE_DATA ap_filter_rec_t *ap_http_input_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_http_input_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_http_header_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_http_header_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_chunk_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_chunk_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_broken_backend_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_http_outerror_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_byterange_filter_handle;
extern AP_DECLARE_DATA ap_filter_rec_t *ap_byterange_filter_handle;


/*
/*
@@ -55,8 +55,8 @@ apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b,
/* HTTP/1.1 chunked transfer encoding filter. */
/* HTTP/1.1 chunked transfer encoding filter. */
apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b);
apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b);


/* Filter to close the connection to the client if backend broke */
/* Filter to handle any error buckets on output */
apr_status_t ap_http_broken_backend_filter(ap_filter_t *f,
apr_status_t ap_http_outerror_filter(ap_filter_t *f,
                                     apr_bucket_brigade *b);
                                     apr_bucket_brigade *b);


char *ap_response_code_string(request_rec *r, int error_index);
char *ap_response_code_string(request_rec *r, int error_index);
+2 −1
Original line number Original line Diff line number Diff line
@@ -1481,7 +1481,8 @@ apr_status_t ap_proxy_http_process_response(apr_pool_t * p, request_rec *r,
                    }
                    }
                    else if (rv != APR_SUCCESS) {
                    else if (rv != APR_SUCCESS) {
                        /* In this case, we are in real trouble because
                        /* In this case, we are in real trouble because
                         * our backend bailed on us.
                         * our backend bailed on us. Pass along a 502 error
                         * error bucket
                         */
                         */
                        ap_log_cerror(APLOG_MARK, APLOG_ERR, rv, c,
                        ap_log_cerror(APLOG_MARK, APLOG_ERR, rv, c,
                                      "proxy: error reading response");
                                      "proxy: error reading response");