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.
This commit is contained in:
Roman Arutyunyan
2026-07-15 18:37:17 +04:00
committed by Roman Arutyunyan
parent f475868196
commit d798231b56
+13 -10
View File
@@ -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