[nginx] Removed incorrect optimization of HEAD requests.
Maxim Dounin
mdounin at mdounin.ru
Tue Jan 19 17:21:38 UTC 2021
details: https://hg.nginx.org/nginx/rev/43a0a9e988be
branches:
changeset: 7761:43a0a9e988be
user: Maxim Dounin <mdounin at mdounin.ru>
date: Tue Jan 19 20:21:12 2021 +0300
description:
Removed incorrect optimization of HEAD requests.
The stub status module and ngx_http_send_response() (used by the empty gif
module and the "return" directive) incorrectly assumed that responding
to HEAD requests always results in r->header_only being set. This is not
true, and results in incorrect behaviour, for example, in the following
configuration:
location / {
image_filter size;
return 200 test;
}
Fix is to remove this incorrect micro-optimization from both stub status
module and ngx_http_send_response().
Reported by Chris Newton.
diffstat:
src/http/modules/ngx_http_stub_status_module.c | 10 ----------
src/http/ngx_http_core_module.c | 2 +-
2 files changed, 1 insertions(+), 11 deletions(-)
diffs (32 lines):
diff -r 83c4622053b0 -r 43a0a9e988be src/http/modules/ngx_http_stub_status_module.c
--- a/src/http/modules/ngx_http_stub_status_module.c Tue Jan 12 16:59:31 2021 +0300
+++ b/src/http/modules/ngx_http_stub_status_module.c Tue Jan 19 20:21:12 2021 +0300
@@ -103,16 +103,6 @@ ngx_http_stub_status_handler(ngx_http_re
ngx_str_set(&r->headers_out.content_type, "text/plain");
r->headers_out.content_type_lowcase = NULL;
- if (r->method == NGX_HTTP_HEAD) {
- r->headers_out.status = NGX_HTTP_OK;
-
- rc = ngx_http_send_header(r);
-
- if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
- return rc;
- }
- }
-
size = sizeof("Active connections: \n") + NGX_ATOMIC_T_LEN
+ sizeof("server accepts handled requests\n") - 1
+ 6 + 3 * NGX_ATOMIC_T_LEN
diff -r 83c4622053b0 -r 43a0a9e988be src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c Tue Jan 12 16:59:31 2021 +0300
+++ b/src/http/ngx_http_core_module.c Tue Jan 19 20:21:12 2021 +0300
@@ -1782,7 +1782,7 @@ ngx_http_send_response(ngx_http_request_
}
}
- if (r->method == NGX_HTTP_HEAD || (r != r->main && val.len == 0)) {
+ if (r != r->main && val.len == 0) {
return ngx_http_send_header(r);
}
More information about the nginx-devel
mailing list