]> git.kaiwu.me - nginx.git/commitdiff
Disable HTTP keepalive for HTTP CONNECT requests
authorRoman Arutyunyan <arut@nginx.com>
Mon, 13 Jul 2026 18:16:34 +0000 (22:16 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 15 Jul 2026 14:37:17 +0000 (18:37 +0400)
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.

src/http/ngx_http_core_module.c

index 4e1c67282c5150c9f6f1d8a55421def10349e42c..b4327c7bc0eab33c0765dc1f0dcd4bb3b4ee6f18 100644 (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