# HG changeset patch # User Maxim Dounin # Date 1714230987 -10800 # Node ID 55a5a40dccdecd5154468100f0db6bb79af495e9 # Parent afd36b161859290167db7d653c5c7b603e8a1e97 Reordered checks for Content-Length and Transfer-Encoding. This ensures that r->headers_in.content_length_n is not set when both Content-Length and Transfer-Encoding headers are present, making it slightly safer to use complex processing for 400 (Bad Request) errors. diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1968,6 +1968,15 @@ ngx_http_process_request_header(ngx_http } if (r->headers_in.content_length) { + if (r->headers_in.transfer_encoding) { + ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, + "client sent \"Content-Length\" and " + "\"Transfer-Encoding\" headers " + "at the same time"); + ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); + return NGX_ERROR; + } + r->headers_in.content_length_n = ngx_atoof(r->headers_in.content_length->value.data, r->headers_in.content_length->value.len); @@ -1993,15 +2002,6 @@ ngx_http_process_request_header(ngx_http && ngx_strncasecmp(r->headers_in.transfer_encoding->value.data, (u_char *) "chunked", 7) == 0) { - if (r->headers_in.content_length) { - ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, - "client sent \"Content-Length\" and " - "\"Transfer-Encoding\" headers " - "at the same time"); - ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); - return NGX_ERROR; - } - r->headers_in.chunked = 1; } else {