diff options
Diffstat (limited to 'src/http/ngx_http_special_response.c')
-rw-r--r-- | src/http/ngx_http_special_response.c | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c index 017376a5b..c1cb23aa4 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -168,9 +168,10 @@ static ngx_str_t error_pages[] = { int ngx_http_special_response_handler(ngx_http_request_t *r, int error) { - int err, rc; + int err, rc, i; ngx_hunk_t *h; ngx_chain_t *out, **ll, *cl; + ngx_http_err_page_t *err_page; ngx_http_core_loc_conf_t *clcf; rc = ngx_http_discard_body(r); @@ -181,19 +182,6 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) r->headers_out.status = error; - if (error < NGX_HTTP_BAD_REQUEST) { - /* 3XX */ - err = error - NGX_HTTP_MOVED_PERMANENTLY; - - } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) { - /* 4XX */ - err = error - NGX_HTTP_BAD_REQUEST + 3; - - } else { - /* 5XX */ - err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17; - } - if (r->keepalive != 0) { switch (error) { case NGX_HTTP_BAD_REQUEST: @@ -213,6 +201,31 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) } } + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + + if (!r->error_page && clcf->error_pages) { + err_page = clcf->error_pages->elts; + for (i = 0; i < clcf->error_pages->nelts; i++) { + if (err_page[i].code == error) { + r->error_page = 1; + return ngx_http_internal_redirect(r, &err_page[i].uri, NULL); + } + } + } + + if (error < NGX_HTTP_BAD_REQUEST) { + /* 3XX */ + err = error - NGX_HTTP_MOVED_PERMANENTLY; + + } else if (error < NGX_HTTP_INTERNAL_SERVER_ERROR) { + /* 4XX */ + err = error - NGX_HTTP_BAD_REQUEST + 3; + + } else { + /* 5XX */ + err = error - NGX_HTTP_INTERNAL_SERVER_ERROR + 3 + 17; + } + if (error_pages[err].len) { r->headers_out.content_length_n = error_pages[err].len + sizeof(error_tail) - 1 @@ -272,8 +285,6 @@ int ngx_http_special_response_handler(ngx_http_request_t *r, int error) ngx_alloc_link_and_set_hunk(cl, h, r->pool, NGX_ERROR); ngx_chain_add_link(out, ll, cl); - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - if (clcf->msie_padding && r->http_version >= NGX_HTTP_VERSION_10 && error >= NGX_HTTP_BAD_REQUEST |