diff options
| author | Roman Arutyunyan <arut@nginx.com> | 2025-09-29 20:47:27 +0400 |
|---|---|---|
| committer | Roman Arutyunyan <arutyunyan.roman@gmail.com> | 2025-10-23 18:40:05 +0400 |
| commit | c8c7beb96f61e2251abbc345357116131cf91c22 (patch) | |
| tree | 5928dd85d6785404835a778045af0f973df05814 /src/http/ngx_http_request.c | |
| parent | 78d1ab5a2c00839a36ff6bac661d9785fce3c1a4 (diff) | |
| download | nginx-c8c7beb96f61e2251abbc345357116131cf91c22.tar.gz nginx-c8c7beb96f61e2251abbc345357116131cf91c22.tar.bz2 | |
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.
Diffstat (limited to 'src/http/ngx_http_request.c')
| -rw-r--r-- | src/http/ngx_http_request.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c index 16d79c490..7f2d04783 100644 --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -1846,8 +1846,9 @@ static ngx_int_t ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h, ngx_uint_t offset) { - ngx_int_t rc; - ngx_str_t host; + u_char *p; + ngx_int_t rc; + ngx_str_t host; if (r->headers_in.host) { ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, @@ -1888,6 +1889,17 @@ ngx_http_process_host(ngx_http_request_t *r, ngx_table_elt_t *h, r->headers_in.server = host; + p = ngx_strlchr(h->value.data + host.len, + h->value.data + h->value.len, ':'); + + if (p) { + rc = ngx_atoi(p + 1, h->value.data + h->value.len - p - 1); + + if (rc > 0 && rc < 65536) { + r->port = rc; + } + } + return NGX_OK; } |
