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).
This commit is contained in:
vinaykumar-1591 2026-06-17 23:06:33 -07:00 committed by Sergey Kandaurov
parent 29c23ad846
commit 3f720dc784

View file

@ -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)
{