From b7387ea76f8a4b54f62785b2a09a4b7c79d15f75 Mon Sep 17 00:00:00 2001 From: Ilia Shipitsin Date: Sat, 27 Dec 2025 20:27:19 +0100 Subject: [PATCH] do not add "Connection: keep=alive" when possible for HTTP/1.0 this header is required, for HTTP/1.1 not --- src/http/ngx_http_header_filter_module.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c index 789938329..f01b136c7 100644 --- a/src/http/ngx_http_header_filter_module.c +++ b/src/http/ngx_http_header_filter_module.c @@ -387,7 +387,9 @@ ngx_http_header_filter(ngx_http_request_t *r) len += sizeof("Connection: upgrade" CRLF) - 1; } else if (r->keepalive) { - len += sizeof("Connection: keep-alive" CRLF) - 1; + if ((r->http_version == NGX_HTTP_VERSION_10) || (clcf->keepalive_header)) { + len += sizeof("Connection: keep-alive" CRLF) - 1; + } /* * MSIE and Opera ignore the "Keep-Alive: timeout=" header. @@ -564,8 +566,10 @@ ngx_http_header_filter(ngx_http_request_t *r) sizeof("Connection: upgrade" CRLF) - 1); } else if (r->keepalive) { - b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, + if ((r->http_version == NGX_HTTP_VERSION_10) || (clcf->keepalive_header)) { + b->last = ngx_cpymem(b->last, "Connection: keep-alive" CRLF, sizeof("Connection: keep-alive" CRLF) - 1); + } if (clcf->keepalive_header) { b->last = ngx_sprintf(b->last, "Keep-Alive: timeout=%T" CRLF,