comparison src/http/ngx_http_core_module.c @ 4247:b79dbadb3d5e stable-1.0

Merging r4147, r4148, r4149, r4150, r4207: Fixes of combination of error_page and return directives: *) Fix for incorrect 201 replies from dav module. Replies with 201 code contain body, and we should clearly indicate it's empty if it's empty. Before 0.8.32 chunked was explicitly disabled for 201 replies and as a result empty body was indicated by connection close (not perfect, but worked). Since 0.8.32 chunked is enabled, and this causes incorrect responses from dav module when HTTP/1.1 is used: with "Transfer-Encoding: chunked" but no chunks at all. Fix is to actually return empty body in special response handler instead of abusing r->header_only flag. See here for initial report: http://mailman.nginx.org/pipermail/nginx-ru/2010-October/037535.html *) Fix for double content when return is used in error_page handler. Test case: location / { error_page 405 /nope; return 405; } location /nope { return 200; } This is expected to return 405 with empty body, but in 0.8.42+ will return builtin 405 error page as well (though not counted in Content-Length, thus breaking protocol). Fix is to use status provided by rewrite script execution in case it's less than NGX_HTTP_BAD_REQUEST even if r->error_status set. This check is in line with one in ngx_http_script_return_code(). Note that this patch also changes behaviour for "return 302 ..." and "rewrite ... redirect" used as error handler. E.g. location / { error_page 405 /redirect; return 405; } location /redirect { rewrite ^ http://example.com/; } will actually return redirect to "http://example.com/" instead of builtin 405 error page with meaningless Location header. This looks like correct change and it's in line with what happens on e.g. directory redirects in error handlers. *) Fix for "return 202" not discarding body. Big POST (not fully preread) to a location / { return 202; } resulted in incorrect behaviour due to "return" code path not calling ngx_http_discard_request_body(). The same applies to all "return" used with 2xx/3xx codes except 201 and 204, and to all "return ... text" uses. Fix is to add ngx_http_discard_request_body() call to ngx_http_send_response() function where it looks appropriate. Discard body call from emtpy gif module removed as it's now redundant. Reported by Pyry Hakulinen, see http://mailman.nginx.org/pipermail/nginx/2011-August/028503.html *) Incorrect special case for "return 204" removed. The special case in question leads to replies without body in configuration like location / { error_page 404 /zero; return 404; } location /zero { return 204; } while replies with empty body are expected per protocol specs. Correct one will look like if (status == NGX_HTTP_NO_CONTENT) { rc = ngx_http_send_header(r); if (rc == NGX_ERROR || r->header_only) { return rc; } return ngx_http_send_special(r, NGX_HTTP_LAST); } though it looks like it's better to drop this special case at all. *) Clear old Location header (if any) while adding a new one. This prevents incorrect behaviour when another redirect is issued within error_page 302 handler.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 01 Nov 2011 13:45:33 +0000
parents d3568507db51
children c8695c991cb8
comparison
equal deleted inserted replaced
4246:d3568507db51 4247:b79dbadb3d5e
981 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE); 981 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);
982 return NGX_OK; 982 return NGX_OK;
983 } 983 }
984 984
985 if (rc == NGX_DONE) { 985 if (rc == NGX_DONE) {
986 ngx_http_clear_location(r);
987
986 r->headers_out.location = ngx_list_push(&r->headers_out.headers); 988 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
987 if (r->headers_out.location == NULL) { 989 if (r->headers_out.location == NULL) {
988 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 990 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
989 return NGX_OK; 991 return NGX_OK;
990 } 992 }
1782 ngx_int_t rc; 1784 ngx_int_t rc;
1783 ngx_str_t val; 1785 ngx_str_t val;
1784 ngx_buf_t *b; 1786 ngx_buf_t *b;
1785 ngx_chain_t out; 1787 ngx_chain_t out;
1786 1788
1789 if (ngx_http_discard_request_body(r) != NGX_OK) {
1790 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1791 }
1792
1787 r->headers_out.status = status; 1793 r->headers_out.status = status;
1788
1789 if (status == NGX_HTTP_NO_CONTENT) {
1790 r->header_only = 1;
1791 return ngx_http_send_header(r);
1792 }
1793 1794
1794 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) { 1795 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
1795 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1796 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1796 } 1797 }
1797 1798
1798 if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) { 1799 if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) {
1800
1801 ngx_http_clear_location(r);
1799 1802
1800 r->headers_out.location = ngx_list_push(&r->headers_out.headers); 1803 r->headers_out.location = ngx_list_push(&r->headers_out.headers);
1801 if (r->headers_out.location == NULL) { 1804 if (r->headers_out.location == NULL) {
1802 return NGX_HTTP_INTERNAL_SERVER_ERROR; 1805 return NGX_HTTP_INTERNAL_SERVER_ERROR;
1803 } 1806 }