[PATCH 06 of 31] Fix double content when return is used in error_page redirection
Maxim Dounin
mdounin at mdounin.ru
Tue Feb 15 16:33:22 MSK 2011
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1297774383 -10800
# Node ID fe16437c03fefa216fe8a44c8fdf75f10be486bd
# Parent 0a1e722edb7c633be9e55ceac2b8a7c33f8c1495
Fix double content when return is used in error_page redirection.
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).
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.
diff --git a/src/http/modules/ngx_http_rewrite_module.c b/src/http/modules/ngx_http_rewrite_module.c
--- a/src/http/modules/ngx_http_rewrite_module.c
+++ b/src/http/modules/ngx_http_rewrite_module.c
@@ -167,8 +167,8 @@ ngx_http_rewrite_handler(ngx_http_reques
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) {
More information about the nginx-devel
mailing list