# HG changeset patch # User Igor Sysoev # Date 1222786629 0 # Node ID 920be89a3d2d7c1d70d9dce993fff251ff619162 # Parent 6223d5a9e87ff8a7be7a1b577e42f6a8315ddc40 ngx_http_upstream_intercept_errors() diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -22,6 +22,8 @@ static void ngx_http_upstream_send_reque ngx_http_upstream_t *u); static void ngx_http_upstream_send_request_handler(ngx_event_t *wev); static void ngx_http_upstream_process_header(ngx_event_t *rev); +static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r, + ngx_http_upstream_t *u); static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c); static void ngx_http_upstream_process_body_in_memory(ngx_event_t *rev); static void ngx_http_upstream_send_response(ngx_http_request_t *r, @@ -1047,8 +1049,6 @@ ngx_http_upstream_process_header(ngx_eve ngx_connection_t *c; ngx_http_request_t *r; ngx_http_upstream_t *u; - ngx_http_err_page_t *err_page; - ngx_http_core_loc_conf_t *clcf; ngx_http_upstream_header_t *hh; ngx_http_upstream_main_conf_t *umcf; @@ -1219,37 +1219,10 @@ ngx_http_upstream_process_header(ngx_eve } - if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST - && u->conf->intercept_errors) - { - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - - if (clcf->error_pages) { - - err_page = clcf->error_pages->elts; - for (i = 0; i < clcf->error_pages->nelts; i++) { - if (err_page[i].status == (ngx_int_t) u->headers_in.status_n) { - - if (u->headers_in.status_n == NGX_HTTP_UNAUTHORIZED) { - - r->headers_out.www_authenticate = - ngx_list_push(&r->headers_out.headers); - - if (r->headers_out.www_authenticate == NULL) { - ngx_http_upstream_finalize_request(r, u, - NGX_HTTP_INTERNAL_SERVER_ERROR); - return; - } - - *r->headers_out.www_authenticate = - *u->headers_in.www_authenticate; - } - - ngx_http_upstream_finalize_request(r, u, - u->headers_in.status_n); - return; - } - } + if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST) { + + if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) { + return; } } @@ -1407,6 +1380,58 @@ ngx_http_upstream_process_header(ngx_eve static ngx_int_t +ngx_http_upstream_intercept_errors(ngx_http_request_t *r, + ngx_http_upstream_t *u) +{ + ngx_int_t status; + ngx_uint_t i; + ngx_table_elt_t *h; + ngx_http_err_page_t *err_page; + ngx_http_core_loc_conf_t *clcf; + + if (!u->conf->intercept_errors) { + return NGX_DECLINED; + } + + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (clcf->error_pages == NULL) { + return NGX_DECLINED; + } + + status = u->headers_in.status_n; + + err_page = clcf->error_pages->elts; + for (i = 0; i < clcf->error_pages->nelts; i++) { + + if (err_page[i].status == status) { + + if (status == NGX_HTTP_UNAUTHORIZED) { + + h = ngx_list_push(&r->headers_out.headers); + + if (h == NULL) { + ngx_http_upstream_finalize_request(r, u, + NGX_HTTP_INTERNAL_SERVER_ERROR); + return NGX_OK; + } + + *h = *u->headers_in.www_authenticate; + + r->headers_out.www_authenticate = h; + } + + ngx_http_upstream_finalize_request(r, u, status); + + return NGX_OK; + } + } + + return NGX_DECLINED; +} + + +static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c) { int err;