mirror of
https://github.com/nginx/nginx.git
synced 2025-06-11 12:22:41 +08:00
ngx_http_upstream_intercept_errors()
This commit is contained in:
parent
eb7cfa0a2f
commit
d01eea1e18
@ -22,6 +22,8 @@ static void ngx_http_upstream_send_request(ngx_http_request_t *r,
|
|||||||
ngx_http_upstream_t *u);
|
ngx_http_upstream_t *u);
|
||||||
static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
|
static void ngx_http_upstream_send_request_handler(ngx_event_t *wev);
|
||||||
static void ngx_http_upstream_process_header(ngx_event_t *rev);
|
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 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_process_body_in_memory(ngx_event_t *rev);
|
||||||
static void ngx_http_upstream_send_response(ngx_http_request_t *r,
|
static void ngx_http_upstream_send_response(ngx_http_request_t *r,
|
||||||
@ -1047,8 +1049,6 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
|
|||||||
ngx_connection_t *c;
|
ngx_connection_t *c;
|
||||||
ngx_http_request_t *r;
|
ngx_http_request_t *r;
|
||||||
ngx_http_upstream_t *u;
|
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_header_t *hh;
|
||||||
ngx_http_upstream_main_conf_t *umcf;
|
ngx_http_upstream_main_conf_t *umcf;
|
||||||
|
|
||||||
@ -1219,37 +1219,10 @@ ngx_http_upstream_process_header(ngx_event_t *rev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (u->headers_in.status_n >= NGX_HTTP_BAD_REQUEST
|
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) {
|
if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {
|
||||||
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1406,6 +1379,58 @@ 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)
|
||||||
|
{
|
||||||
|
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
|
static ngx_int_t
|
||||||
ngx_http_upstream_test_connect(ngx_connection_t *c)
|
ngx_http_upstream_test_connect(ngx_connection_t *c)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user