]> git.kaiwu.me - nginx.git/commitdiff
Removed incorrect optimization of HEAD requests.
authorMaxim Dounin <mdounin@mdounin.ru>
Tue, 19 Jan 2021 17:21:12 +0000 (20:21 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Tue, 19 Jan 2021 17:21:12 +0000 (20:21 +0300)
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.

src/http/modules/ngx_http_stub_status_module.c
src/http/ngx_http_core_module.c

index 9bdf88129db0d76289be21d19baff0dadcf080a3..db68b768a40cc54e63a65fda79831b0bf5cdb055 100644 (file)
@@ -103,16 +103,6 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
     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
index 3671558d874f208127a961e0a86b1b089ffa7d6e..aa40c998537fd707cb6530f1706173e8a16cbda4 100644 (file)
@@ -1782,7 +1782,7 @@ ngx_http_send_response(ngx_http_request_t *r, ngx_uint_t status,
         }
     }
 
-    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);
     }