From c8c7beb96f61e2251abbc345357116131cf91c22 Mon Sep 17 00:00:00 2001 From: Roman Arutyunyan Date: Mon, 29 Sep 2025 20:47:27 +0400 Subject: Added $request_port and $is_request_port variables. The $request_port variable contains the port passed by the client in the request line (for HTTP/1.x) or ":authority" pseudo-header (for HTTP/2 and HTTP/3). If the request line contains no host, or ":authority" is missing, then $request_port is taken from the "Host" header, similar to the $host variable. The $is_request_port variable contains ":" if $request_port is non-empty, and is empty otherwise. --- src/http/v2/ngx_http_v2.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/http/v2') diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c index 13856583f..fe9ee5a88 100644 --- a/src/http/v2/ngx_http_v2.c +++ b/src/http/v2/ngx_http_v2.c @@ -3518,7 +3518,8 @@ ngx_http_v2_parse_scheme(ngx_http_request_t *r, ngx_str_t *value) static ngx_int_t ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value) { - ngx_int_t rc; + u_char *p; + ngx_int_t rc; if (r->host_start) { ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, @@ -3552,6 +3553,16 @@ ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value) r->headers_in.server = *value; + p = ngx_strlchr(r->host_start + value->len, r->host_end, ':'); + + if (p) { + rc = ngx_atoi(p + 1, r->host_end - p - 1); + + if (rc > 0 && rc < 65536) { + r->port = rc; + } + } + return NGX_OK; } -- cgit