[nginx] svn commit: r4248 - in branches/stable-1.0: . src/http src/http/modules
igor at sysoev.ru
igor at sysoev.ru
Tue Nov 1 13:45:33 UTC 2011
Author: is
Date: 2011-11-01 13:45:33 +0000 (Tue, 01 Nov 2011)
New Revision: 4248
Modified:
branches/stable-1.0/
branches/stable-1.0/src/http/modules/ngx_http_empty_gif_module.c
branches/stable-1.0/src/http/modules/ngx_http_rewrite_module.c
branches/stable-1.0/src/http/modules/ngx_http_static_module.c
branches/stable-1.0/src/http/ngx_http_core_module.c
branches/stable-1.0/src/http/ngx_http_core_module.h
branches/stable-1.0/src/http/ngx_http_script.c
branches/stable-1.0/src/http/ngx_http_special_response.c
Log:
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.
Property changes on: branches/stable-1.0
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk:3960-3974,3977-3987,3991-3996,3998,4003-4007,4009-4013,4015-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143,4154,4156-4157,4183-4184,4186-4187,4191-4192,4199-4205,4229,4235,4237
+ /trunk:3960-3974,3977-3987,3991-3996,3998,4003-4007,4009-4013,4015-4018,4020,4023,4025-4027,4034-4065,4073,4077,4086-4090,4094-4102,4106-4108,4113-4114,4129-4137,4143,4147-4150,4154,4156-4157,4183-4184,4186-4187,4191-4192,4199-4205,4207,4229,4235,4237
Modified: branches/stable-1.0/src/http/modules/ngx_http_empty_gif_module.c
===================================================================
--- branches/stable-1.0/src/http/modules/ngx_http_empty_gif_module.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/modules/ngx_http_empty_gif_module.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -111,19 +111,12 @@
static ngx_int_t
ngx_http_empty_gif_handler(ngx_http_request_t *r)
{
- ngx_int_t rc;
ngx_http_complex_value_t cv;
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
return NGX_HTTP_NOT_ALLOWED;
}
- rc = ngx_http_discard_request_body(r);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
cv.value.len = sizeof(ngx_empty_gif);
Modified: branches/stable-1.0/src/http/modules/ngx_http_rewrite_module.c
===================================================================
--- branches/stable-1.0/src/http/modules/ngx_http_rewrite_module.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/modules/ngx_http_rewrite_module.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -167,8 +167,8 @@
code(e);
}
- if (e->status == NGX_DECLINED) {
- return NGX_DECLINED;
+ if (e->status < NGX_HTTP_BAD_REQUEST) {
+ return e->status;
}
if (r->err_status == 0) {
Modified: branches/stable-1.0/src/http/modules/ngx_http_static_module.c
===================================================================
--- branches/stable-1.0/src/http/modules/ngx_http_static_module.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/modules/ngx_http_static_module.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -139,6 +139,8 @@
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http dir");
+ ngx_http_clear_location(r);
+
r->headers_out.location = ngx_palloc(r->pool, sizeof(ngx_table_elt_t));
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
Modified: branches/stable-1.0/src/http/ngx_http_core_module.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_core_module.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/ngx_http_core_module.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -983,6 +983,8 @@
}
if (rc == NGX_DONE) {
+ ngx_http_clear_location(r);
+
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
@@ -1784,19 +1786,20 @@
ngx_buf_t *b;
ngx_chain_t out;
+ if (ngx_http_discard_request_body(r) != NGX_OK) {
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
+ }
+
r->headers_out.status = status;
- if (status == NGX_HTTP_NO_CONTENT) {
- r->header_only = 1;
- return ngx_http_send_header(r);
- }
-
if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
if (status >= NGX_HTTP_MOVED_PERMANENTLY && status <= NGX_HTTP_SEE_OTHER) {
+ ngx_http_clear_location(r);
+
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
Modified: branches/stable-1.0/src/http/ngx_http_core_module.h
===================================================================
--- branches/stable-1.0/src/http/ngx_http_core_module.h 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/ngx_http_core_module.h 2011-11-01 13:45:33 UTC (rev 4248)
@@ -529,5 +529,12 @@
r->headers_out.last_modified = NULL; \
}
+#define ngx_http_clear_location(r) \
+ \
+ if (r->headers_out.location) { \
+ r->headers_out.location->hash = 0; \
+ r->headers_out.location = NULL; \
+ }
+
#endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
Modified: branches/stable-1.0/src/http/ngx_http_script.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_script.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/ngx_http_script.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -1106,6 +1106,8 @@
"rewritten redirect: \"%V\"", &e->buf);
}
+ ngx_http_clear_location(r);
+
r->headers_out.location = ngx_list_push(&r->headers_out.headers);
if (r->headers_out.location == NULL) {
e->ip = ngx_http_script_exit;
Modified: branches/stable-1.0/src/http/ngx_http_special_response.c
===================================================================
--- branches/stable-1.0/src/http/ngx_http_special_response.c 2011-11-01 13:24:50 UTC (rev 4247)
+++ branches/stable-1.0/src/http/ngx_http_special_response.c 2011-11-01 13:45:33 UTC (rev 4248)
@@ -421,7 +421,6 @@
if (error == NGX_HTTP_CREATED) {
/* 201 */
err = 0;
- r->header_only = 1;
} else if (error == NGX_HTTP_NO_CONTENT) {
/* 204 */
@@ -583,6 +582,8 @@
ngx_str_set(&location->key, "Location");
location->value = uri;
+ ngx_http_clear_location(r);
+
r->headers_out.location = location;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
@@ -636,7 +637,7 @@
r->headers_out.content_type_lowcase = NULL;
} else {
- r->headers_out.content_length_n = -1;
+ r->headers_out.content_length_n = 0;
}
if (r->headers_out.content_length) {
@@ -654,7 +655,7 @@
}
if (ngx_http_error_pages[err].len == 0) {
- return NGX_OK;
+ return ngx_http_send_special(r, NGX_HTTP_LAST);
}
b = ngx_calloc_buf(r->pool);
More information about the nginx-devel
mailing list