From: Roman Arutyunyan Date: Mon, 13 Jul 2026 18:16:34 +0000 (+0400) Subject: Disable HTTP keepalive for HTTP CONNECT requests X-Git-Tag: release-1.31.3~8 X-Git-Url: http://git.kaiwu.me/http/$%7BGITURL%7D/doc/static/gitweb.js?a=commitdiff_plain;h=d798231b56bb4a6284999e3b868b503c4a7ee8d3;p=nginx.git Disable HTTP keepalive for HTTP CONNECT requests As per RFC 2817 Section 5.2: Like any other pipelined HTTP/1.1 request, data to be tunneled may be sent immediately after the blank line. The usual caveats also apply: data may be discarded if the eventual response is negative, and the connection may be reset with no response if more than one TCP segment is outstanding. --- diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 4e1c67282..b4327c7bc 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -845,18 +845,21 @@ ngx_http_handler(ngx_http_request_t *r) r->connection->log->action = NULL; if (!r->internal) { - switch (r->headers_in.connection_type) { - case 0: - r->keepalive = (r->http_version > NGX_HTTP_VERSION_10); - break; - case NGX_HTTP_CONNECTION_CLOSE: - r->keepalive = 0; - break; + if (r->method != NGX_HTTP_CONNECT) { + switch (r->headers_in.connection_type) { + case 0: + r->keepalive = (r->http_version > NGX_HTTP_VERSION_10); + break; - case NGX_HTTP_CONNECTION_KEEP_ALIVE: - r->keepalive = 1; - break; + case NGX_HTTP_CONNECTION_CLOSE: + r->keepalive = 0; + break; + + case NGX_HTTP_CONNECTION_KEEP_ALIVE: + r->keepalive = 1; + break; + } } r->lingering_close = (r->headers_in.content_length_n > 0