From: vinaykumar-1591 Date: Thu, 18 Jun 2026 06:06:33 +0000 (-0700) Subject: Upstream: Upgrade header processing X-Git-Url: http://git.kaiwu.me/%7B@url%7D?a=commitdiff_plain;h=3f720dc7845eb21594788fe12cc9e37e5d930161;p=nginx.git Upstream: Upgrade header processing Pass Upgrade through for HTTP/1.x clients only: both for active connection upgrades (101 Switching Protocols) and for advertising available upgrades in other responses (RFC 9110 Section 7.8). Strip it for HTTP/2+ clients where connection-specific headers are forbidden (RFC 9113 Section 8.2.2, RFC 9114 Section 4.2). --- diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index bb8964add..bd6ae5f07 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -156,6 +156,8 @@ static ngx_int_t ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); +static ngx_int_t ngx_http_upstream_copy_upgrade(ngx_http_request_t *r, + ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf); static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r, @@ -278,6 +280,10 @@ static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { ngx_http_upstream_copy_allow_ranges, offsetof(ngx_http_headers_out_t, accept_ranges), 1 }, + { ngx_string("Upgrade"), + ngx_http_upstream_ignore_header_line, 0, + ngx_http_upstream_copy_upgrade, 0, 0 }, + { ngx_string("Content-Range"), ngx_http_upstream_ignore_header_line, 0, ngx_http_upstream_copy_header_line, @@ -5868,6 +5874,27 @@ ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r, } +static ngx_int_t +ngx_http_upstream_copy_upgrade(ngx_http_request_t *r, ngx_table_elt_t *h, + ngx_uint_t offset) +{ + ngx_table_elt_t *ho; + + if (r->http_version >= NGX_HTTP_VERSION_20) { + return NGX_OK; + } + + ho = ngx_list_push(&r->headers_out.headers); + if (ho == NULL) { + return NGX_ERROR; + } + + *ho = *h; + + return NGX_OK; +} + + static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf) {