diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 3f865345b..6f328e6a4 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -139,6 +139,8 @@ static ngx_int_t ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t ngx_http_upstream_process_vary(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); +static ngx_int_t ngx_http_upstream_process_priority(ngx_http_request_t *r, + ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset); static ngx_int_t @@ -336,6 +338,10 @@ static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = { ngx_http_upstream_copy_header_line, offsetof(ngx_http_headers_out_t, content_encoding), 0 }, + { ngx_string("Priority"), + ngx_http_upstream_process_priority, 0, + ngx_http_upstream_copy_header_line, 0, 0 }, + { ngx_null_string, NULL, 0, NULL, 0, 0 } }; @@ -5594,6 +5600,45 @@ ngx_http_upstream_process_vary(ngx_http_request_t *r, } +static ngx_int_t +ngx_http_upstream_process_priority(ngx_http_request_t *r, + ngx_table_elt_t *h, ngx_uint_t offset) +{ +#if (NGX_HTTP_V2) + ngx_http_priority_t priority; + ngx_http_v2_stream_t *stream; + + if (r != r->main) { + return NGX_OK; + } + + /* RFC 9218, Section 8: server hints override the client's values */ + + stream = r->stream; + + if (stream == NULL) { + return NGX_OK; + } + + if (ngx_http_priority_parse(&h->value, &priority) != NGX_OK + || !(priority.urgency_set || priority.incremental_set)) + { + return NGX_OK; + } + + stream->priority.server = priority; + ngx_http_priority_state_update(&stream->priority); + + ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "http upstream priority: u=%ud i=%ud", + stream->priority.effective.urgency, + stream->priority.effective.incremental); +#endif + + return NGX_OK; +} + + static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset)