summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_variables.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2025-05-25HTTP CONNECT proxy.tunnelRoman Arutyunyan1-0/+17
HTTP CONNECT method is now supported in HTTP/1 connections. It's disabled in all currently existing standard modules. A new variable $port is added that contains the port passed by client in HTTP CONNECT. The $host variable contains the host part. A new module ngx_http_tunnel module is added which establishes a tunnel to a backend. It supports the newly added HTTP CONNECT method and can be used to set up an HTTP CONNECT proxy. As recommended by RFC 9110, proxy target should be restricted to ensure safe proxying: : Proxies that support CONNECT SHOULD restrict its use to a limited set : of known ports or a configurable list of safe request targets. Example config: server { listen 8000; resolver dns.example.com; map $port $tun_port { 80 1; 443 1; } map $host $tun_host { hostnames; example.com 1; *.example.org 1; } map $tun_port$tun_host $tun { 11 $host:$port; } location / { tunnel_pass $tun; } } Request: $ curl -px 127.0.0.1:8000 http://example.com
2023-05-01Variables: avoid possible buffer overrun with some "$sent_http_*".Sergey Kandaurov1-2/+4
The existing logic to evaluate multi header "$sent_http_*" variables, such as $sent_http_cache_control, as previously introduced in 1.23.0, doesn't take into account that one or more elements can be cleared, yet still present in a linked list, pointed to by the next field. Such elements don't contribute to the resulting variable length, an attempt to append a separator for them ends up in out of bounds write. This is not possible with standard modules, though at least one third party module is known to override multi header values this way, so it makes sense to harden the logic. The fix restores a generic boundary check.
2022-10-12PROXY protocol v2 TLV variables.Roman Arutyunyan1-0/+39
The variables have prefix $proxy_protocol_tlv_ and are accessible by name and by type. Examples are: $proxy_protocol_tlv_0x01, $proxy_protocol_tlv_alpn.
2022-05-30All non-unique input headers are now linked lists.Maxim Dounin1-29/+4
The ngx_http_process_multi_header_lines() function is removed, as it is exactly equivalent to ngx_http_process_header_line(). Similarly, ngx_http_variable_header() is used instead of ngx_http_variable_headers().
2022-05-30Reworked multi headers to use linked lists.Maxim Dounin1-24/+17
Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
2022-05-30Combining unknown headers during variables lookup (ticket #1316).Maxim Dounin1-17/+69
Previously, $http_*, $sent_http_*, $sent_trailer_*, $upstream_http_*, and $upstream_trailer_* variables returned only the first header (with a few specially handled exceptions: $http_cookie, $http_x_forwarded_for, $sent_http_cache_control, $sent_http_link). With this change, all headers are returned, combined together. For example, $http_foo variable will be "a, b" if there are "Foo: a" and "Foo: b" headers in the request. Note that $upstream_http_set_cookie will also return all "Set-Cookie" headers (ticket #1843), though this might not be what one want, since the "Set-Cookie" header does not follow the list syntax (see RFC 7230, section 3.2.2).
2021-10-06Fixed $content_length cacheability with chunked (ticket #2252).Maxim Dounin1-0/+4
2021-04-08Added $connection_time variable.Maxim Dounin1-0/+30
2020-05-08Variables: fixed buffer over-read when evaluating "$arg_".Sergey Kandaurov1-1/+1
2019-10-21Parsing server PROXY protocol address and port (ticket #1206).Roman Arutyunyan1-5/+18
New variables $proxy_protocol_server_addr and $proxy_protocol_server_port are added both to HTTP and Stream.
2019-10-21Core: moved PROXY protocol fields out of ngx_connection_t.Roman Arutyunyan1-4/+19
Now a new structure ngx_proxy_protocol_t holds these fields. This allows to add more PROXY protocol fields in the future without modifying the connection structure.
2019-04-24Variables support in limit_rate and limit_rate_after (ticket #293).Ruslan Ermilov1-29/+26
2018-12-11Copy regex unnamed captures to cloned subrequests.Roman Arutyunyan1-1/+3
Previously, unnamed regex captures matched in the parent request, were not available in a cloned subrequest. Now 3 fields related to unnamed captures are copied to a cloned subrequest: r->ncaptures, r->captures and r->captures_data. Since r->captures cannot be changed by either request after creating a clone, a new flag r->realloc_captures is introduced to force reallocation of r->captures. The issue was reported as a proxy_cache_background_update misbehavior in http://mailman.nginx.org/pipermail/nginx/2018-December/057251.html.
2018-03-07Improved code readablity.Ruslan Ermilov1-2/+6
No functional changes.
2018-02-08Basic support of the Link response header.Ruslan Ermilov1-0/+3
2017-10-04Fixed handling of unix sockets in $binary_remote_addr.Maxim Dounin1-0/+12
Previously, unix sockets were treated as AF_INET ones, and this may result in buffer overread on Linux, where unbound unix sockets have 2-byte addresses. Note that it is not correct to use just sun_path as a binary representation for unix sockets. This will result in an empty string for unbound unix sockets, and thus behaviour of limit_req and limit_conn will change when switching from $remote_addr to $binary_remote_addr. As such, normal text representation is used. Reported by Stephan Dollberg.
2017-08-01Variables: macros for null variables.Ruslan Ermilov1-1/+1
No functional changes.
2017-07-07Variables: use ngx_http_variable_null_value where appropriate.Ruslan Ermilov1-11/+5
2017-03-24Added support for trailers in HTTP responses.Piotr Sikora1-0/+15
Example: ngx_table_elt_t *h; h = ngx_list_push(&r->headers_out.trailers); if (h == NULL) { return NGX_ERROR; } ngx_str_set(&h->key, "Fun"); ngx_str_set(&h->value, "with trailers"); h->hash = ngx_hash_key_lc(h->key.data, h->key.len); The code above adds "Fun: with trailers" trailer to the response. Modules that want to emit trailers must set r->expect_trailers = 1 in header filter, otherwise they might not be emitted for HTTP/1.1 responses that aren't already chunked. This change also adds $sent_trailer_* variables. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2017-01-31Variables: generic prefix variables.Dmitry Volyntsev1-122/+118
2016-12-21Limited recursion when evaluating variables.Ruslan Ermilov1-6/+30
Unlimited recursion might cause stack exhaustion in some misconfigurations.
2016-06-20Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.Roman Arutyunyan1-50/+4
2016-05-23Added the $proxy_protocol_port variable.Dmitry Volyntsev1-0/+31
2016-04-26Variable $request_id.Vladimir Homutov1-0/+47
The variable contains text representation based on random data, usable as a unique request identifier.
2016-03-31Fixed logging with variable field width.Sergey Kandaurov1-3/+2
2015-10-19Fixed variables prefix comparison.Maxim Dounin1-12/+26
Variable names are not null-terminated, so using ngx_strncmp() without extra length checks is wrong. Reported by Markus Linnala, http://mailman.nginx.org/pipermail/nginx-devel/2015-August/007211.html.
2015-03-23Request body: unbuffered reading.Maxim Dounin1-0/+4
The r->request_body_no_buffering flag was introduced. It instructs client request body reading code to avoid reading the whole body, and to call post_handler early instead. The caller should use the ngx_http_read_unbuffered_request_body() function to read remaining parts of the body. Upstream module is now able to use this mode, if configured with the proxy_request_buffering directive.
2014-08-27Variables: fixed non-indexed access of prefix vars (ticket #600).Maxim Dounin1-2/+5
Previously, a configuration like location / { ssi on; ssi_types *; set $http_foo "bar"; return 200 '<!--#echo var="http_foo" -->\n'; } resulted in NULL pointer dereference in ngx_http_get_variable() as the variable was explicitly added to the variables hash, but its get_handler wasn't properly set in the hash. Fix is to make sure that get_handler is properly set by ngx_http_variables_init_vars().
2014-05-19Setting $args now invalidates unparsed uri.Maxim Dounin1-1/+19
Prodded by Yichun Zhang.
2014-04-29Upstream: added the "$upstream_cookie_<name>" variables.Vladimir Homutov1-0/+19
2014-03-17Added server-side support for PROXY protocol v1 (ticket #355).Roman Arutyunyan1-0/+19
Client address specified in the PROXY protocol header is now saved in the $proxy_protocol_addr variable and can be used in the realip module. This is currently not implemented for mail.
2013-12-09Fixed handling of UNIX-domain sockets.Ruslan Ermilov1-0/+12
When evaluating $local_port, $server_port, and $server_addr, UNIX-domain sockets were mistakenly interpreted as IPv4 sockets.
2013-10-31Removed extra allocation for $sent_http_last_modified.Maxim Dounin1-2/+1
There is no need to allocate memory for "Last-Modified: " string, the variable only contains date itself.
2013-09-04Win32: $request_time fixed.Maxim Dounin1-1/+1
On win32, time_t is 64 bits wide by default, and passing an ngx_msec_int_t argument for %T format specifier doesn't work. This doesn't manifest itself on other platforms as time_t and ngx_msec_int_t are usually of the same size.
2013-08-20Format specifier fixes in error logging.Sergey Kandaurov1-1/+1
2013-08-06Fixed memory leaks in the root and auth_basic_user_file directives.Valentin Bartenev1-2/+6
If a relative path is set by variables, then the ngx_conf_full_name() function was called while processing requests, which causes allocations from the cycle pool. A new function that takes pool as an argument was introduced.
2013-05-02PCRE: retain input pattern for all regular expressions.Piotr Sikora1-1/+1
Previously, input pattern was kept only for regular expressions with named captures, which resulted in error log entries without input pattern for PCRE errors that occured while processing regular expressions without them. Signed-off-by: Piotr Sikora <piotr@cloudflare.com>
2013-02-27Correctly handle multiple X-Forwarded-For headers (ticket #106).Ruslan Ermilov1-3/+3
2013-02-27Fixed separator in $sent_http_cache_control.Ruslan Ermilov1-6/+27
In case multiple "Cache-Control" headers are sent to a client, multiple values in $sent_http_cache_control were incorrectly split by a semicolon. Now they are split by a comma.
2013-02-18Proxy: support for connection upgrade (101 Switching Protocols).Maxim Dounin1-1/+5
This allows to proxy WebSockets by using configuration like this: location /chat/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } Connection upgrade is allowed as long as it was requested by a client via the Upgrade request header.
2013-01-21Variables $pipe, $request_length, $time_iso8601, and $time_local.Ruslan Ermilov1-0/+102
Log module counterparts are preserved for efficiency. Based on patch by Kiril Kalchev.
2012-12-17Added checks that disallow adding a variable with an empty name.Ruslan Ermilov1-0/+12
Added variable name syntax checks to "geo" and "map" directives.
2012-11-21Request body: $content_length variable to honor real body size.Maxim Dounin1-2/+37
This allows to handle requests with chunked body by fastcgi and uwsgi modules, and also simplifies handling of various request body modifications.
2012-11-21Request body: $request_body variable generalization.Maxim Dounin1-5/+13
The $request_body variable was assuming there can't be more than two buffers. While this is currently true due to request body reading implementation details, this is not a good thing to depend on and may change in the future.
2012-11-16Variables $request_time and $msec.Ruslan Ermilov1-0/+63
Log module counterparts are preserved for efficiency.
2012-10-29Variables $connection and $connection_requests.Maxim Dounin1-0/+53
Log module counterparts are removed as they aren't used often and there is no need to preserve them for efficiency.
2012-10-03Variable $bytes_sent.Maxim Dounin1-0/+26
It replicates variable $bytes_sent as previously available in log module only. Patch by Benjamin Grössing (with minor changes).
2012-06-21Fixed compile-time conditionals used to detect if X-Forwarded-For supportRuslan Ermilov1-1/+1
is needed.
2012-06-18Style fix.Andrey Belov1-1/+1
2012-06-18New core variable: $status.Andrey Belov1-0/+39
Contains response status code as a 3-digit integer (with leading zeroes if necessary), or one of the following values: 000 - response status code has not yet been assigned 009 - HTTP/0.9 request is being processed