Mercurial > hg > nginx
annotate src/http/ngx_http_variables.c @ 9299:2706b60dc225 default tip
Core: error logging rate limiting.
With this change, error logging to files can be rate-limited with
the "rate=" parameter. The parameter specifies allowed log messages
rate to a particular file (per worker), in messages per second (m/s).
By default, "rate=1000m/s" is used.
Rate limiting is implemented using the "leaky bucket" method, similarly
to the limit_req module.
Maximum burst size is set to the number of log messages per second
for each severity level, so "error" messages are logged even if the
rate limit is hit by "info" messages (but not vice versa). When the
limit is reached for a particular level, the "too many log messages,
limiting" message is logged at this level.
If debug logging is enabled, either for the particular log file or for
the particular connection, rate limiting is not used.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 25 Jun 2024 22:58:56 +0300 |
parents | 2fce021888f9 |
children |
rev | line source |
---|---|
499 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
499 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
1329 | 11 #include <nginx.h> |
499 | 12 |
13 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
14 static ngx_http_variable_t *ngx_http_add_prefix_variable(ngx_conf_t *cf, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
15 ngx_str_t *name, ngx_uint_t flags); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
16 |
573 | 17 static ngx_int_t ngx_http_variable_request(ngx_http_request_t *r, |
18 ngx_http_variable_value_t *v, uintptr_t data); | |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
19 #if 0 |
1350 | 20 static void ngx_http_variable_request_set(ngx_http_request_t *r, |
21 ngx_http_variable_value_t *v, uintptr_t data); | |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
22 #endif |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
23 static ngx_int_t ngx_http_variable_request_get_size(ngx_http_request_t *r, |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
24 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 25 static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r, |
26 ngx_http_variable_value_t *v, uintptr_t data); | |
5083
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
27 |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
28 static ngx_int_t ngx_http_variable_cookies(ngx_http_request_t *r, |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
29 ngx_http_variable_value_t *v, uintptr_t data); |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
30 static ngx_int_t ngx_http_variable_headers_internal(ngx_http_request_t *r, |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
31 ngx_http_variable_value_t *v, uintptr_t data, u_char sep); |
577 | 32 |
33 static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r, | |
573 | 34 ngx_http_variable_value_t *v, uintptr_t data); |
577 | 35 static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r, |
36 ngx_http_variable_value_t *v, uintptr_t data); | |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
37 static ngx_int_t ngx_http_variable_unknown_trailer_out(ngx_http_request_t *r, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
38 ngx_http_variable_value_t *v, uintptr_t data); |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
39 static ngx_int_t ngx_http_variable_request_line(ngx_http_request_t *r, |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
40 ngx_http_variable_value_t *v, uintptr_t data); |
2359
4fee4ebbfb0b
$cookie_... variable did not for SSI and perl
Igor Sysoev <igor@sysoev.ru>
parents:
2333
diff
changeset
|
41 static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r, |
4fee4ebbfb0b
$cookie_... variable did not for SSI and perl
Igor Sysoev <igor@sysoev.ru>
parents:
2333
diff
changeset
|
42 ngx_http_variable_value_t *v, uintptr_t data); |
2137 | 43 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r, |
44 ngx_http_variable_value_t *v, uintptr_t data); | |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
45 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
46 static ngx_int_t ngx_http_variable_tcpinfo(ngx_http_request_t *r, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
47 ngx_http_variable_value_t *v, uintptr_t data); |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
48 #endif |
577 | 49 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
50 static ngx_int_t ngx_http_variable_content_length(ngx_http_request_t *r, |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
51 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 52 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, |
53 ngx_http_variable_value_t *v, uintptr_t data); | |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
54 static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
55 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 56 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r, |
57 ngx_http_variable_value_t *v, uintptr_t data); | |
58 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r, | |
59 ngx_http_variable_value_t *v, uintptr_t data); | |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
60 static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r, |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
61 ngx_http_variable_value_t *v, uintptr_t data); |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
62 static ngx_int_t ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r, |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
63 ngx_http_variable_value_t *v, uintptr_t data); |
8072
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
64 static ngx_int_t ngx_http_variable_proxy_protocol_tlv(ngx_http_request_t *r, |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
65 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 66 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r, |
67 ngx_http_variable_value_t *v, uintptr_t data); | |
68 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r, | |
69 ngx_http_variable_value_t *v, uintptr_t data); | |
731 | 70 static ngx_int_t ngx_http_variable_scheme(ngx_http_request_t *r, |
71 ngx_http_variable_value_t *v, uintptr_t data); | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
72 static ngx_int_t ngx_http_variable_https(ngx_http_request_t *r, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
73 ngx_http_variable_value_t *v, uintptr_t data); |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
74 static void ngx_http_variable_set_args(ngx_http_request_t *r, |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
75 ngx_http_variable_value_t *v, uintptr_t data); |
1351 | 76 static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r, |
77 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 78 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r, |
79 ngx_http_variable_value_t *v, uintptr_t data); | |
2259 | 80 static ngx_int_t ngx_http_variable_realpath_root(ngx_http_request_t *r, |
81 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 82 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r, |
83 ngx_http_variable_value_t *v, uintptr_t data); | |
1811 | 84 static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r, |
85 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 86 static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r, |
87 ngx_http_variable_value_t *v, uintptr_t data); | |
88 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, | |
89 ngx_http_variable_value_t *v, uintptr_t data); | |
4886 | 90 static ngx_int_t ngx_http_variable_bytes_sent(ngx_http_request_t *r, |
91 ngx_http_variable_value_t *v, uintptr_t data); | |
611 | 92 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
93 ngx_http_variable_value_t *v, uintptr_t data); | |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
94 static ngx_int_t ngx_http_variable_pipe(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
95 ngx_http_variable_value_t *v, uintptr_t data); |
629 | 96 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, |
97 ngx_http_variable_value_t *v, uintptr_t data); | |
2844 | 98 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r, |
99 ngx_http_variable_value_t *v, uintptr_t data); | |
759 | 100 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r, |
101 ngx_http_variable_value_t *v, uintptr_t data); | |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
102 static ngx_int_t ngx_http_variable_request_length(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
103 ngx_http_variable_value_t *v, uintptr_t data); |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
104 static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
105 ngx_http_variable_value_t *v, uintptr_t data); |
6531 | 106 static ngx_int_t ngx_http_variable_request_id(ngx_http_request_t *r, |
107 ngx_http_variable_value_t *v, uintptr_t data); | |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
108 static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
109 ngx_http_variable_value_t *v, uintptr_t data); |
4686 | 110 |
641 | 111 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
112 ngx_http_variable_value_t *v, uintptr_t data); | |
113 static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
114 ngx_http_variable_value_t *v, uintptr_t data); | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
115 static ngx_int_t ngx_http_variable_sent_location(ngx_http_request_t *r, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
116 ngx_http_variable_value_t *v, uintptr_t data); |
641 | 117 static ngx_int_t ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
118 ngx_http_variable_value_t *v, uintptr_t data); | |
119 static ngx_int_t ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
120 ngx_http_variable_value_t *v, uintptr_t data); | |
121 static ngx_int_t ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
122 ngx_http_variable_value_t *v, uintptr_t data); | |
123 static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
124 ngx_http_variable_value_t *v, uintptr_t data); | |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
125 static void ngx_http_variable_set_limit_rate(ngx_http_request_t *r, |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
126 ngx_http_variable_value_t *v, uintptr_t data); |
641 | 127 |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
128 static ngx_int_t ngx_http_variable_connection(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
129 ngx_http_variable_value_t *v, uintptr_t data); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
130 static ngx_int_t ngx_http_variable_connection_requests(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
131 ngx_http_variable_value_t *v, uintptr_t data); |
7821
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
132 static ngx_int_t ngx_http_variable_connection_time(ngx_http_request_t *r, |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
133 ngx_http_variable_value_t *v, uintptr_t data); |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
134 |
1329 | 135 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r, |
136 ngx_http_variable_value_t *v, uintptr_t data); | |
2011 | 137 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, |
138 ngx_http_variable_value_t *v, uintptr_t data); | |
2249 | 139 static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r, |
140 ngx_http_variable_value_t *v, uintptr_t data); | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
141 static ngx_int_t ngx_http_variable_msec(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
142 ngx_http_variable_value_t *v, uintptr_t data); |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
143 static ngx_int_t ngx_http_variable_time_iso8601(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
144 ngx_http_variable_value_t *v, uintptr_t data); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
145 static ngx_int_t ngx_http_variable_time_local(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
146 ngx_http_variable_value_t *v, uintptr_t data); |
499 | 147 |
509 | 148 /* |
149 * TODO: | |
150 * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED | |
151 * REMOTE_HOST (null), REMOTE_IDENT (null), | |
152 * SERVER_SOFTWARE | |
153 * | |
571 | 154 * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner) |
509 | 155 */ |
499 | 156 |
641 | 157 /* |
5084
f7fe817c92a2
Correctly handle multiple X-Forwarded-For headers (ticket #106).
Ruslan Ermilov <ru@nginx.com>
parents:
5083
diff
changeset
|
158 * the $http_host, $http_user_agent, $http_referer, and $http_via |
f7fe817c92a2
Correctly handle multiple X-Forwarded-For headers (ticket #106).
Ruslan Ermilov <ru@nginx.com>
parents:
5083
diff
changeset
|
159 * variables may be handled by generic |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4558
diff
changeset
|
160 * ngx_http_variable_unknown_header_in(), but for performance reasons |
641 | 161 * they are handled using dedicated entries |
162 */ | |
163 | |
509 | 164 static ngx_http_variable_t ngx_http_core_variables[] = { |
165 | |
637 | 166 { ngx_string("http_host"), NULL, ngx_http_variable_header, |
533 | 167 offsetof(ngx_http_request_t, headers_in.host), 0, 0 }, |
499 | 168 |
637 | 169 { ngx_string("http_user_agent"), NULL, ngx_http_variable_header, |
533 | 170 offsetof(ngx_http_request_t, headers_in.user_agent), 0, 0 }, |
509 | 171 |
637 | 172 { ngx_string("http_referer"), NULL, ngx_http_variable_header, |
533 | 173 offsetof(ngx_http_request_t, headers_in.referer), 0, 0 }, |
499 | 174 |
175 #if (NGX_HTTP_GZIP) | |
637 | 176 { ngx_string("http_via"), NULL, ngx_http_variable_header, |
533 | 177 offsetof(ngx_http_request_t, headers_in.via), 0, 0 }, |
499 | 178 #endif |
179 | |
4697
09187f9b0950
Fixed compile-time conditionals used to detect if X-Forwarded-For support
Ruslan Ermilov <ru@nginx.com>
parents:
4686
diff
changeset
|
180 #if (NGX_HTTP_X_FORWARDED_FOR) |
8025
c263f9ffa1fd
All non-unique input headers are now linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
181 { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_header, |
533 | 182 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 }, |
499 | 183 #endif |
184 | |
5083
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
185 { ngx_string("http_cookie"), NULL, ngx_http_variable_cookies, |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
186 offsetof(ngx_http_request_t, headers_in.cookie), 0, 0 }, |
515 | 187 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
188 { ngx_string("content_length"), NULL, ngx_http_variable_content_length, |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
189 0, 0, 0 }, |
509 | 190 |
637 | 191 { ngx_string("content_type"), NULL, ngx_http_variable_header, |
533 | 192 offsetof(ngx_http_request_t, headers_in.content_type), 0, 0 }, |
509 | 193 |
637 | 194 { ngx_string("host"), NULL, ngx_http_variable_host, 0, 0, 0 }, |
509 | 195 |
982 | 196 { ngx_string("binary_remote_addr"), NULL, |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
197 ngx_http_variable_binary_remote_addr, 0, 0, 0 }, |
982 | 198 |
637 | 199 { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 }, |
499 | 200 |
637 | 201 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 }, |
509 | 202 |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
203 { ngx_string("proxy_protocol_addr"), NULL, |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
204 ngx_http_variable_proxy_protocol_addr, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
205 offsetof(ngx_proxy_protocol_t, src_addr), 0, 0 }, |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
206 |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
207 { ngx_string("proxy_protocol_port"), NULL, |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
208 ngx_http_variable_proxy_protocol_port, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
209 offsetof(ngx_proxy_protocol_t, src_port), 0, 0 }, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
210 |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
211 { ngx_string("proxy_protocol_server_addr"), NULL, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
212 ngx_http_variable_proxy_protocol_addr, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
213 offsetof(ngx_proxy_protocol_t, dst_addr), 0, 0 }, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
214 |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
215 { ngx_string("proxy_protocol_server_port"), NULL, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
216 ngx_http_variable_proxy_protocol_port, |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
217 offsetof(ngx_proxy_protocol_t, dst_port), 0, 0 }, |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
218 |
8072
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
219 { ngx_string("proxy_protocol_tlv_"), NULL, |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
220 ngx_http_variable_proxy_protocol_tlv, |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
221 0, NGX_HTTP_VAR_PREFIX, 0 }, |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
222 |
637 | 223 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 }, |
509 | 224 |
637 | 225 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 }, |
509 | 226 |
637 | 227 { ngx_string("server_protocol"), NULL, ngx_http_variable_request, |
533 | 228 offsetof(ngx_http_request_t, http_protocol), 0, 0 }, |
509 | 229 |
731 | 230 { ngx_string("scheme"), NULL, ngx_http_variable_scheme, 0, 0, 0 }, |
231 | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
232 { ngx_string("https"), NULL, ngx_http_variable_https, 0, 0, 0 }, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
233 |
637 | 234 { ngx_string("request_uri"), NULL, ngx_http_variable_request, |
533 | 235 offsetof(ngx_http_request_t, unparsed_uri), 0, 0 }, |
499 | 236 |
637 | 237 { ngx_string("uri"), NULL, ngx_http_variable_request, |
238 offsetof(ngx_http_request_t, uri), | |
1565 | 239 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
637 | 240 |
241 { ngx_string("document_uri"), NULL, ngx_http_variable_request, | |
573 | 242 offsetof(ngx_http_request_t, uri), |
1565 | 243 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 244 |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
245 { ngx_string("request"), NULL, ngx_http_variable_request_line, 0, 0, 0 }, |
569 | 246 |
637 | 247 { ngx_string("document_root"), NULL, |
1565 | 248 ngx_http_variable_document_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 249 |
2259 | 250 { ngx_string("realpath_root"), NULL, |
251 ngx_http_variable_realpath_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
252 | |
637 | 253 { ngx_string("query_string"), NULL, ngx_http_variable_request, |
509 | 254 offsetof(ngx_http_request_t, args), |
1565 | 255 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
499 | 256 |
1350 | 257 { ngx_string("args"), |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
258 ngx_http_variable_set_args, |
1350 | 259 ngx_http_variable_request, |
589 | 260 offsetof(ngx_http_request_t, args), |
1565 | 261 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
589 | 262 |
1351 | 263 { ngx_string("is_args"), NULL, ngx_http_variable_is_args, |
1565 | 264 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1351 | 265 |
637 | 266 { ngx_string("request_filename"), NULL, |
267 ngx_http_variable_request_filename, 0, | |
1565 | 268 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 269 |
1811 | 270 { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 }, |
509 | 271 |
637 | 272 { ngx_string("request_method"), NULL, |
3463
0904bd7d5b37
make $request_method non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3451
diff
changeset
|
273 ngx_http_variable_request_method, 0, |
0904bd7d5b37
make $request_method non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3451
diff
changeset
|
274 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 275 |
637 | 276 { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 }, |
509 | 277 |
4886 | 278 { ngx_string("bytes_sent"), NULL, ngx_http_variable_bytes_sent, |
279 0, 0, 0 }, | |
280 | |
637 | 281 { ngx_string("body_bytes_sent"), NULL, ngx_http_variable_body_bytes_sent, |
611 | 282 0, 0, 0 }, |
283 | |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
284 { ngx_string("pipe"), NULL, ngx_http_variable_pipe, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
285 0, 0, 0 }, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
286 |
637 | 287 { ngx_string("request_completion"), NULL, |
288 ngx_http_variable_request_completion, | |
629 | 289 0, 0, 0 }, |
290 | |
2844 | 291 { ngx_string("request_body"), NULL, |
292 ngx_http_variable_request_body, | |
293 0, 0, 0 }, | |
294 | |
759 | 295 { ngx_string("request_body_file"), NULL, |
296 ngx_http_variable_request_body_file, | |
297 0, 0, 0 }, | |
298 | |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
299 { ngx_string("request_length"), NULL, ngx_http_variable_request_length, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
300 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
301 |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
302 { ngx_string("request_time"), NULL, ngx_http_variable_request_time, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
303 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
304 |
6531 | 305 { ngx_string("request_id"), NULL, |
306 ngx_http_variable_request_id, | |
307 0, 0, 0 }, | |
308 | |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
309 { ngx_string("status"), NULL, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
310 ngx_http_variable_status, 0, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
311 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
312 |
641 | 313 { ngx_string("sent_http_content_type"), NULL, |
314 ngx_http_variable_sent_content_type, 0, 0, 0 }, | |
315 | |
316 { ngx_string("sent_http_content_length"), NULL, | |
317 ngx_http_variable_sent_content_length, 0, 0, 0 }, | |
318 | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
319 { ngx_string("sent_http_location"), NULL, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
320 ngx_http_variable_sent_location, 0, 0, 0 }, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
321 |
641 | 322 { ngx_string("sent_http_last_modified"), NULL, |
323 ngx_http_variable_sent_last_modified, 0, 0, 0 }, | |
324 | |
325 { ngx_string("sent_http_connection"), NULL, | |
326 ngx_http_variable_sent_connection, 0, 0, 0 }, | |
327 | |
328 { ngx_string("sent_http_keep_alive"), NULL, | |
329 ngx_http_variable_sent_keep_alive, 0, 0, 0 }, | |
330 | |
331 { ngx_string("sent_http_transfer_encoding"), NULL, | |
332 ngx_http_variable_sent_transfer_encoding, 0, 0, 0 }, | |
333 | |
8025
c263f9ffa1fd
All non-unique input headers are now linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
334 { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_header, |
641 | 335 offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 }, |
336 | |
8025
c263f9ffa1fd
All non-unique input headers are now linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
337 { ngx_string("sent_http_link"), NULL, ngx_http_variable_header, |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7121
diff
changeset
|
338 offsetof(ngx_http_request_t, headers_out.link), 0, 0 }, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7121
diff
changeset
|
339 |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
340 { ngx_string("limit_rate"), ngx_http_variable_set_limit_rate, |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
341 ngx_http_variable_request_get_size, |
637 | 342 offsetof(ngx_http_request_t, limit_rate), |
1565 | 343 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
637 | 344 |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
345 { ngx_string("connection"), NULL, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
346 ngx_http_variable_connection, 0, 0, 0 }, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
347 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
348 { ngx_string("connection_requests"), NULL, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
349 ngx_http_variable_connection_requests, 0, 0, 0 }, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
350 |
7821
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
351 { ngx_string("connection_time"), NULL, ngx_http_variable_connection_time, |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
352 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
353 |
1329 | 354 { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version, |
355 0, 0, 0 }, | |
356 | |
2011 | 357 { ngx_string("hostname"), NULL, ngx_http_variable_hostname, |
358 0, 0, 0 }, | |
359 | |
2249 | 360 { ngx_string("pid"), NULL, ngx_http_variable_pid, |
361 0, 0, 0 }, | |
362 | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
363 { ngx_string("msec"), NULL, ngx_http_variable_msec, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
364 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
365 |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
366 { ngx_string("time_iso8601"), NULL, ngx_http_variable_time_iso8601, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
367 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
368 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
369 { ngx_string("time_local"), NULL, ngx_http_variable_time_local, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
370 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
371 |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
372 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
373 { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
374 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
375 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
376 { ngx_string("tcpinfo_rttvar"), NULL, ngx_http_variable_tcpinfo, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
377 1, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
378 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
379 { ngx_string("tcpinfo_snd_cwnd"), NULL, ngx_http_variable_tcpinfo, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
380 2, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
381 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
382 { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
383 3, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
384 #endif |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
385 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
386 { ngx_string("http_"), NULL, ngx_http_variable_unknown_header_in, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
387 0, NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
388 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
389 { ngx_string("sent_http_"), NULL, ngx_http_variable_unknown_header_out, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
390 0, NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
391 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
392 { ngx_string("sent_trailer_"), NULL, ngx_http_variable_unknown_trailer_out, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
393 0, NGX_HTTP_VAR_PREFIX, 0 }, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
394 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
395 { ngx_string("cookie_"), NULL, ngx_http_variable_cookie, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
396 0, NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
397 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
398 { ngx_string("arg_"), NULL, ngx_http_variable_argument, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
399 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 }, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
400 |
7077
2a288909abc6
Variables: macros for null variables.
Ruslan Ermilov <ru@nginx.com>
parents:
7053
diff
changeset
|
401 ngx_http_null_variable |
499 | 402 }; |
403 | |
404 | |
577 | 405 ngx_http_variable_value_t ngx_http_variable_null_value = |
406 ngx_http_variable(""); | |
407 ngx_http_variable_value_t ngx_http_variable_true_value = | |
408 ngx_http_variable("1"); | |
409 | |
410 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
411 static ngx_uint_t ngx_http_variable_depth = 100; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
412 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
413 |
499 | 414 ngx_http_variable_t * |
509 | 415 ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags) |
416 { | |
611 | 417 ngx_int_t rc; |
509 | 418 ngx_uint_t i; |
611 | 419 ngx_hash_key_t *key; |
509 | 420 ngx_http_variable_t *v; |
421 ngx_http_core_main_conf_t *cmcf; | |
422 | |
4972
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
423 if (name->len == 0) { |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
424 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
425 "invalid variable name \"$\""); |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
426 return NULL; |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
427 } |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
428 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
429 if (flags & NGX_HTTP_VAR_PREFIX) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
430 return ngx_http_add_prefix_variable(cf, name, flags); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
431 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
432 |
509 | 433 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
434 | |
611 | 435 key = cmcf->variables_keys->keys.elts; |
436 for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) { | |
437 if (name->len != key[i].key.len | |
438 || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0) | |
509 | 439 { |
440 continue; | |
441 } | |
442 | |
611 | 443 v = key[i].value; |
444 | |
1565 | 445 if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) { |
509 | 446 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
447 "the duplicate \"%V\" variable", name); | |
448 return NULL; | |
449 } | |
450 | |
7226 | 451 if (!(flags & NGX_HTTP_VAR_WEAK)) { |
452 v->flags &= ~NGX_HTTP_VAR_WEAK; | |
453 } | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
454 |
611 | 455 return v; |
509 | 456 } |
457 | |
611 | 458 v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t)); |
509 | 459 if (v == NULL) { |
460 return NULL; | |
461 } | |
462 | |
463 v->name.len = name->len; | |
2049 | 464 v->name.data = ngx_pnalloc(cf->pool, name->len); |
509 | 465 if (v->name.data == NULL) { |
466 return NULL; | |
467 } | |
468 | |
2135 | 469 ngx_strlow(v->name.data, name->data, name->len); |
509 | 470 |
637 | 471 v->set_handler = NULL; |
472 v->get_handler = NULL; | |
509 | 473 v->data = 0; |
474 v->flags = flags; | |
533 | 475 v->index = 0; |
509 | 476 |
611 | 477 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0); |
478 | |
479 if (rc == NGX_ERROR) { | |
480 return NULL; | |
481 } | |
482 | |
483 if (rc == NGX_BUSY) { | |
484 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
485 "conflicting variable name \"%V\"", name); | |
486 return NULL; | |
487 } | |
488 | |
509 | 489 return v; |
490 } | |
491 | |
492 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
493 static ngx_http_variable_t * |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
494 ngx_http_add_prefix_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
495 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
496 ngx_uint_t i; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
497 ngx_http_variable_t *v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
498 ngx_http_core_main_conf_t *cmcf; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
499 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
500 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
501 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
502 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
503 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
504 if (name->len != v[i].name.len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
505 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
506 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
507 continue; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
508 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
509 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
510 v = &v[i]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
511 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
512 if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
513 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
514 "the duplicate \"%V\" variable", name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
515 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
516 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
517 |
7226 | 518 if (!(flags & NGX_HTTP_VAR_WEAK)) { |
519 v->flags &= ~NGX_HTTP_VAR_WEAK; | |
520 } | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
521 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
522 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
523 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
524 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
525 v = ngx_array_push(&cmcf->prefix_variables); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
526 if (v == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
527 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
528 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
529 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
530 v->name.len = name->len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
531 v->name.data = ngx_pnalloc(cf->pool, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
532 if (v->name.data == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
533 return NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
534 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
535 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
536 ngx_strlow(v->name.data, name->data, name->len); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
537 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
538 v->set_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
539 v->get_handler = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
540 v->data = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
541 v->flags = flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
542 v->index = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
543 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
544 return v; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
545 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
546 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
547 |
509 | 548 ngx_int_t |
549 ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name) | |
499 | 550 { |
501 | 551 ngx_uint_t i; |
552 ngx_http_variable_t *v; | |
499 | 553 ngx_http_core_main_conf_t *cmcf; |
554 | |
4972
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
555 if (name->len == 0) { |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
557 "invalid variable name \"$\""); |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
558 return NGX_ERROR; |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
559 } |
8b635cf36ccc
Added checks that disallow adding a variable with an empty name.
Ruslan Ermilov <ru@nginx.com>
parents:
4928
diff
changeset
|
560 |
499 | 561 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
562 | |
501 | 563 v = cmcf->variables.elts; |
564 | |
565 if (v == NULL) { | |
499 | 566 if (ngx_array_init(&cmcf->variables, cf->pool, 4, |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2533
diff
changeset
|
567 sizeof(ngx_http_variable_t)) |
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2533
diff
changeset
|
568 != NGX_OK) |
499 | 569 { |
509 | 570 return NGX_ERROR; |
499 | 571 } |
501 | 572 |
573 } else { | |
574 for (i = 0; i < cmcf->variables.nelts; i++) { | |
575 if (name->len != v[i].name.len | |
576 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) | |
577 { | |
578 continue; | |
579 } | |
580 | |
509 | 581 return i; |
501 | 582 } |
499 | 583 } |
584 | |
501 | 585 v = ngx_array_push(&cmcf->variables); |
586 if (v == NULL) { | |
509 | 587 return NGX_ERROR; |
499 | 588 } |
589 | |
501 | 590 v->name.len = name->len; |
2049 | 591 v->name.data = ngx_pnalloc(cf->pool, name->len); |
501 | 592 if (v->name.data == NULL) { |
509 | 593 return NGX_ERROR; |
501 | 594 } |
499 | 595 |
2135 | 596 ngx_strlow(v->name.data, name->data, name->len); |
501 | 597 |
637 | 598 v->set_handler = NULL; |
599 v->get_handler = NULL; | |
501 | 600 v->data = 0; |
509 | 601 v->flags = 0; |
533 | 602 v->index = cmcf->variables.nelts - 1; |
501 | 603 |
4540
cab9aa79256c
Slight optimization in ngx_http_get_variable_index().
Ruslan Ermilov <ru@nginx.com>
parents:
4470
diff
changeset
|
604 return v->index; |
499 | 605 } |
606 | |
607 | |
608 ngx_http_variable_value_t * | |
609 ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index) | |
610 { | |
501 | 611 ngx_http_variable_t *v; |
499 | 612 ngx_http_core_main_conf_t *cmcf; |
613 | |
614 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
615 | |
553 | 616 if (cmcf->variables.nelts <= index) { |
499 | 617 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
5327
6b479db5b52b
Format specifier fixes in error logging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5316
diff
changeset
|
618 "unknown variable index: %ui", index); |
499 | 619 return NULL; |
620 } | |
621 | |
573 | 622 if (r->variables[index].not_found || r->variables[index].valid) { |
623 return &r->variables[index]; | |
501 | 624 } |
499 | 625 |
501 | 626 v = cmcf->variables.elts; |
499 | 627 |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
628 if (ngx_http_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
629 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
630 "cycle while evaluating variable \"%V\"", |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
631 &v[index].name); |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
632 return NULL; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
633 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
634 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
635 ngx_http_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
636 |
637 | 637 if (v[index].get_handler(r, &r->variables[index], v[index].data) |
638 == NGX_OK) | |
639 { | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
640 ngx_http_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
641 |
1565 | 642 if (v[index].flags & NGX_HTTP_VAR_NOCACHEABLE) { |
643 r->variables[index].no_cacheable = 1; | |
499 | 644 } |
573 | 645 |
646 return &r->variables[index]; | |
499 | 647 } |
648 | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
649 ngx_http_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
650 |
657 | 651 r->variables[index].valid = 0; |
652 r->variables[index].not_found = 1; | |
653 | |
798 | 654 return NULL; |
573 | 655 } |
656 | |
657 | |
658 ngx_http_variable_value_t * | |
659 ngx_http_get_flushed_variable(ngx_http_request_t *r, ngx_uint_t index) | |
660 { | |
1150 | 661 ngx_http_variable_value_t *v; |
573 | 662 |
663 v = &r->variables[index]; | |
664 | |
4470
d9bf6caf0371
Variables: honor no_cacheable for not_found variables.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
665 if (v->valid || v->not_found) { |
1565 | 666 if (!v->no_cacheable) { |
573 | 667 return v; |
668 } | |
669 | |
670 v->valid = 0; | |
671 v->not_found = 0; | |
509 | 672 } |
501 | 673 |
573 | 674 return ngx_http_get_indexed_variable(r, index); |
499 | 675 } |
676 | |
677 | |
678 ngx_http_variable_value_t * | |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3499
diff
changeset
|
679 ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key) |
499 | 680 { |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
681 size_t len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
682 ngx_uint_t i, n; |
501 | 683 ngx_http_variable_t *v; |
573 | 684 ngx_http_variable_value_t *vv; |
499 | 685 ngx_http_core_main_conf_t *cmcf; |
686 | |
687 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
688 | |
611 | 689 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len); |
499 | 690 |
611 | 691 if (v) { |
692 if (v->flags & NGX_HTTP_VAR_INDEXED) { | |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3499
diff
changeset
|
693 return ngx_http_get_flushed_variable(r, v->index); |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
694 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
695 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
696 if (ngx_http_variable_depth == 0) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
697 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
698 "cycle while evaluating variable \"%V\"", name); |
573 | 699 return NULL; |
700 } | |
6851
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
701 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
702 ngx_http_variable_depth--; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
703 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
704 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
705 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
706 if (vv && v->get_handler(r, vv, v->data) == NGX_OK) { |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
707 ngx_http_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
708 return vv; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
709 } |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
710 |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
711 ngx_http_variable_depth++; |
8cd97c14b0e2
Limited recursion when evaluating variables.
Ruslan Ermilov <ru@nginx.com>
parents:
6593
diff
changeset
|
712 return NULL; |
509 | 713 } |
714 | |
715 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); | |
716 if (vv == NULL) { | |
717 return NULL; | |
718 } | |
719 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
720 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
721 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
722 v = cmcf->prefix_variables.elts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
723 n = cmcf->prefix_variables.nelts; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
724 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
725 for (i = 0; i < cmcf->prefix_variables.nelts; i++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
726 if (name->len >= v[i].name.len && name->len > len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
727 && ngx_strncmp(name->data, v[i].name.data, v[i].name.len) == 0) |
577 | 728 { |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
729 len = v[i].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
730 n = i; |
1162 | 731 } |
732 } | |
733 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
734 if (n != cmcf->prefix_variables.nelts) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
735 if (v[n].get_handler(r, vv, (uintptr_t) name) == NGX_OK) { |
2137 | 736 return vv; |
737 } | |
738 | |
739 return NULL; | |
740 } | |
741 | |
635 | 742 vv->not_found = 1; |
573 | 743 |
501 | 744 return vv; |
499 | 745 } |
746 | |
747 | |
573 | 748 static ngx_int_t |
749 ngx_http_variable_request(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
750 uintptr_t data) | |
751 { | |
752 ngx_str_t *s; | |
753 | |
754 s = (ngx_str_t *) ((char *) r + data); | |
755 | |
756 if (s->data) { | |
757 v->len = s->len; | |
758 v->valid = 1; | |
1565 | 759 v->no_cacheable = 0; |
573 | 760 v->not_found = 0; |
761 v->data = s->data; | |
762 | |
763 } else { | |
764 v->not_found = 1; | |
765 } | |
766 | |
767 return NGX_OK; | |
768 } | |
769 | |
770 | |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
771 #if 0 |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
772 |
637 | 773 static void |
1350 | 774 ngx_http_variable_request_set(ngx_http_request_t *r, |
775 ngx_http_variable_value_t *v, uintptr_t data) | |
776 { | |
777 ngx_str_t *s; | |
778 | |
779 s = (ngx_str_t *) ((char *) r + data); | |
780 | |
781 s->len = v->len; | |
782 s->data = v->data; | |
783 } | |
784 | |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
785 #endif |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
786 |
1350 | 787 |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
788 static ngx_int_t |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
789 ngx_http_variable_request_get_size(ngx_http_request_t *r, |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
790 ngx_http_variable_value_t *v, uintptr_t data) |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
791 { |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
792 size_t *sp; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
793 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
794 sp = (size_t *) ((char *) r + data); |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
795 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
796 v->data = ngx_pnalloc(r->pool, NGX_SIZE_T_LEN); |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
797 if (v->data == NULL) { |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
798 return NGX_ERROR; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
799 } |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
800 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
801 v->len = ngx_sprintf(v->data, "%uz", *sp) - v->data; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
802 v->valid = 1; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
803 v->no_cacheable = 0; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
804 v->not_found = 0; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
805 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
806 return NGX_OK; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
807 } |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
808 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
809 |
573 | 810 static ngx_int_t |
811 ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
812 uintptr_t data) | |
515 | 813 { |
8025
c263f9ffa1fd
All non-unique input headers are now linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
814 return ngx_http_variable_headers_internal(r, v, data, ','); |
573 | 815 } |
816 | |
817 | |
818 static ngx_int_t | |
5083
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
819 ngx_http_variable_cookies(ngx_http_request_t *r, |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
820 ngx_http_variable_value_t *v, uintptr_t data) |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
821 { |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
822 return ngx_http_variable_headers_internal(r, v, data, ';'); |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
823 } |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
824 |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
825 |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
826 static ngx_int_t |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
827 ngx_http_variable_headers_internal(ngx_http_request_t *r, |
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
828 ngx_http_variable_value_t *v, uintptr_t data, u_char sep) |
573 | 829 { |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
830 size_t len; |
8164
b71e69247483
Variables: avoid possible buffer overrun with some "$sent_http_*".
Sergey Kandaurov <pluknet@nginx.com>
parents:
8072
diff
changeset
|
831 u_char *p, *end; |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
832 ngx_table_elt_t *h, *th; |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
833 |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
834 h = *(ngx_table_elt_t **) ((char *) r + data); |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
835 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
836 len = 0; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
837 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
838 for (th = h; th; th = th->next) { |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
839 |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
840 if (th->hash == 0) { |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
841 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
842 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
843 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
844 len += th->value.len + 2; |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
845 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
846 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
847 if (len == 0) { |
573 | 848 v->not_found = 1; |
849 return NGX_OK; | |
515 | 850 } |
851 | |
5083
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
852 len -= 2; |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
853 |
573 | 854 v->valid = 1; |
1565 | 855 v->no_cacheable = 0; |
573 | 856 v->not_found = 0; |
515 | 857 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
858 if (h->next == NULL) { |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
859 v->len = h->value.len; |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
860 v->data = h->value.data; |
515 | 861 |
573 | 862 return NGX_OK; |
515 | 863 } |
864 | |
2049 | 865 p = ngx_pnalloc(r->pool, len); |
573 | 866 if (p == NULL) { |
867 return NGX_ERROR; | |
868 } | |
869 | |
870 v->len = len; | |
871 v->data = p; | |
515 | 872 |
8164
b71e69247483
Variables: avoid possible buffer overrun with some "$sent_http_*".
Sergey Kandaurov <pluknet@nginx.com>
parents:
8072
diff
changeset
|
873 end = p + len; |
b71e69247483
Variables: avoid possible buffer overrun with some "$sent_http_*".
Sergey Kandaurov <pluknet@nginx.com>
parents:
8072
diff
changeset
|
874 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
875 for (th = h; th; th = th->next) { |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
876 |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
877 if (th->hash == 0) { |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
878 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
879 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
880 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
881 p = ngx_copy(p, th->value.data, th->value.len); |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
882 |
8164
b71e69247483
Variables: avoid possible buffer overrun with some "$sent_http_*".
Sergey Kandaurov <pluknet@nginx.com>
parents:
8072
diff
changeset
|
883 if (p == end) { |
515 | 884 break; |
885 } | |
886 | |
5083
a805dc9c85cd
Fixed separator in $sent_http_cache_control.
Ruslan Ermilov <ru@nginx.com>
parents:
5072
diff
changeset
|
887 *p++ = sep; *p++ = ' '; |
515 | 888 } |
889 | |
573 | 890 return NGX_OK; |
515 | 891 } |
892 | |
893 | |
573 | 894 static ngx_int_t |
577 | 895 ngx_http_variable_unknown_header_in(ngx_http_request_t *r, |
896 ngx_http_variable_value_t *v, uintptr_t data) | |
897 { | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
898 return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data, |
577 | 899 &r->headers_in.headers.part, |
900 sizeof("http_") - 1); | |
901 } | |
902 | |
903 | |
904 static ngx_int_t | |
905 ngx_http_variable_unknown_header_out(ngx_http_request_t *r, | |
573 | 906 ngx_http_variable_value_t *v, uintptr_t data) |
499 | 907 { |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
908 return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data, |
577 | 909 &r->headers_out.headers.part, |
910 sizeof("sent_http_") - 1); | |
911 } | |
501 | 912 |
577 | 913 |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
914 static ngx_int_t |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
915 ngx_http_variable_unknown_trailer_out(ngx_http_request_t *r, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
916 ngx_http_variable_value_t *v, uintptr_t data) |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
917 { |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
918 return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data, |
7034
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
919 &r->headers_out.trailers.part, |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
920 sizeof("sent_trailer_") - 1); |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
921 } |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
922 |
1b068a4e82d8
Added support for trailers in HTTP responses.
Piotr Sikora <piotrsikora@google.com>
parents:
6899
diff
changeset
|
923 |
1162 | 924 ngx_int_t |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
925 ngx_http_variable_unknown_header(ngx_http_request_t *r, |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
926 ngx_http_variable_value_t *v, ngx_str_t *var, |
577 | 927 ngx_list_part_t *part, size_t prefix) |
928 { | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
929 u_char *p, ch; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
930 size_t len; |
573 | 931 ngx_uint_t i, n; |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
932 ngx_table_elt_t *header, *h, **ph; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
933 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
934 ph = &h; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
935 len = 0; |
499 | 936 |
937 header = part->elts; | |
938 | |
939 for (i = 0; /* void */ ; i++) { | |
940 | |
941 if (i >= part->nelts) { | |
942 if (part->next == NULL) { | |
943 break; | |
944 } | |
945 | |
946 part = part->next; | |
947 header = part->elts; | |
948 i = 0; | |
949 } | |
950 | |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
951 if (header[i].hash == 0) { |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
952 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
953 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
954 |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
955 if (header[i].key.len != var->len - prefix) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
956 continue; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
957 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
958 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
959 for (n = 0; n < var->len - prefix; n++) { |
499 | 960 ch = header[i].key.data[n]; |
961 | |
509 | 962 if (ch >= 'A' && ch <= 'Z') { |
963 ch |= 0x20; | |
499 | 964 |
965 } else if (ch == '-') { | |
966 ch = '_'; | |
967 } | |
968 | |
577 | 969 if (var->data[n + prefix] != ch) { |
499 | 970 break; |
971 } | |
972 } | |
973 | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
974 if (n != var->len - prefix) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
975 continue; |
499 | 976 } |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
977 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
978 len += header[i].value.len + 2; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
979 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
980 *ph = &header[i]; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
981 ph = &header[i].next; |
499 | 982 } |
983 | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
984 *ph = NULL; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
985 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
986 if (h == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
987 v->not_found = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
988 return NGX_OK; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
989 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
990 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
991 len -= 2; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
992 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
993 if (h->next == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
994 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
995 v->len = h->value.len; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
996 v->valid = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
997 v->no_cacheable = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
998 v->not_found = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
999 v->data = h->value.data; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1000 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1001 return NGX_OK; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1002 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1003 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1004 p = ngx_pnalloc(r->pool, len); |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1005 if (p == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1006 return NGX_ERROR; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1007 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1008 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1009 v->len = len; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1010 v->valid = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1011 v->no_cacheable = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1012 v->not_found = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1013 v->data = p; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1014 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1015 for ( ;; ) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1016 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1017 p = ngx_copy(p, h->value.data, h->value.len); |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1018 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1019 if (h->next == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1020 break; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1021 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1022 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1023 *p++ = ','; *p++ = ' '; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1024 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1025 h = h->next; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1026 } |
573 | 1027 |
1028 return NGX_OK; | |
509 | 1029 } |
1030 | |
1031 | |
573 | 1032 static ngx_int_t |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1033 ngx_http_variable_request_line(ngx_http_request_t *r, |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1034 ngx_http_variable_value_t *v, uintptr_t data) |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1035 { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1036 u_char *p, *s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1037 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1038 s = r->request_line.data; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1039 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1040 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1041 s = r->request_start; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1042 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1043 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1044 v->not_found = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1045 return NGX_OK; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1046 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1047 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1048 for (p = s; p < r->header_in->last; p++) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1049 if (*p == CR || *p == LF) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1050 break; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1051 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1052 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1053 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1054 r->request_line.len = p - s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1055 r->request_line.data = s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1056 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1057 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1058 v->len = r->request_line.len; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1059 v->valid = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1060 v->no_cacheable = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1061 v->not_found = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1062 v->data = s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1063 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1064 return NGX_OK; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1065 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1066 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1067 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1068 static ngx_int_t |
2307 | 1069 ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1070 uintptr_t data) | |
1071 { | |
1072 ngx_str_t *name = (ngx_str_t *) data; | |
1073 | |
1074 ngx_str_t cookie, s; | |
1075 | |
1076 s.len = name->len - (sizeof("cookie_") - 1); | |
1077 s.data = name->data + sizeof("cookie_") - 1; | |
1078 | |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
1079 if (ngx_http_parse_multi_header_lines(r, r->headers_in.cookie, &s, &cookie) |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
1080 == NULL) |
2307 | 1081 { |
1082 v->not_found = 1; | |
1083 return NGX_OK; | |
1084 } | |
1085 | |
1086 v->len = cookie.len; | |
1087 v->valid = 1; | |
1088 v->no_cacheable = 0; | |
1089 v->not_found = 0; | |
1090 v->data = cookie.data; | |
1091 | |
1092 return NGX_OK; | |
1093 } | |
1094 | |
1095 | |
1096 static ngx_int_t | |
2137 | 1097 ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1098 uintptr_t data) | |
1099 { | |
1100 ngx_str_t *name = (ngx_str_t *) data; | |
1101 | |
2415 | 1102 u_char *arg; |
1103 size_t len; | |
1104 ngx_str_t value; | |
2137 | 1105 |
2415 | 1106 len = name->len - (sizeof("arg_") - 1); |
1107 arg = name->data + sizeof("arg_") - 1; | |
1108 | |
7648
028b16e2798f
Variables: fixed buffer over-read when evaluating "$arg_".
Sergey Kandaurov <pluknet@nginx.com>
parents:
7591
diff
changeset
|
1109 if (len == 0 || ngx_http_arg(r, arg, len, &value) != NGX_OK) { |
2137 | 1110 v->not_found = 1; |
1111 return NGX_OK; | |
1112 } | |
1113 | |
2415 | 1114 v->data = value.data; |
1115 v->len = value.len; | |
1116 v->valid = 1; | |
1117 v->no_cacheable = 0; | |
1118 v->not_found = 0; | |
2137 | 1119 |
1120 return NGX_OK; | |
1121 } | |
1122 | |
1123 | |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1124 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1125 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1126 static ngx_int_t |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1127 ngx_http_variable_tcpinfo(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1128 uintptr_t data) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1129 { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1130 struct tcp_info ti; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1131 socklen_t len; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1132 uint32_t value; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1133 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1134 len = sizeof(struct tcp_info); |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1135 if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1136 v->not_found = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1137 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1138 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1139 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1140 v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN); |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1141 if (v->data == NULL) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1142 return NGX_ERROR; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1143 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1144 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1145 switch (data) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1146 case 0: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1147 value = ti.tcpi_rtt; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1148 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1149 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1150 case 1: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1151 value = ti.tcpi_rttvar; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1152 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1153 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1154 case 2: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1155 value = ti.tcpi_snd_cwnd; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1156 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1157 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1158 case 3: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1159 value = ti.tcpi_rcv_space; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1160 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1161 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1162 /* suppress warning */ |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1163 default: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1164 value = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1165 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1166 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1167 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1168 v->len = ngx_sprintf(v->data, "%uD", value) - v->data; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1169 v->valid = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1170 v->no_cacheable = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1171 v->not_found = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1172 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1173 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1174 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1175 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1176 #endif |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1177 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1178 |
2137 | 1179 static ngx_int_t |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1180 ngx_http_variable_content_length(ngx_http_request_t *r, |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1181 ngx_http_variable_value_t *v, uintptr_t data) |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1182 { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1183 u_char *p; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1184 |
9262
106b3832e7ef
Modified $content_length to match available request body length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8164
diff
changeset
|
1185 if (r->reading_body && r->headers_in.content_length) { |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1186 v->len = r->headers_in.content_length->value.len; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1187 v->data = r->headers_in.content_length->value.data; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1188 v->valid = 1; |
9262
106b3832e7ef
Modified $content_length to match available request body length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8164
diff
changeset
|
1189 v->no_cacheable = 1; |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1190 v->not_found = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1191 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1192 } else if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1193 v->not_found = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1194 v->no_cacheable = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1195 |
9262
106b3832e7ef
Modified $content_length to match available request body length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8164
diff
changeset
|
1196 } else if (r->discard_body) { |
9263
388a801e9bb9
Request body: discarded body now treated as no body.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9262
diff
changeset
|
1197 v->not_found = 1; |
9262
106b3832e7ef
Modified $content_length to match available request body length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8164
diff
changeset
|
1198 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1199 } else if (r->headers_in.content_length_n >= 0) { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1200 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1201 if (p == NULL) { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1202 return NGX_ERROR; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1203 } |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1204 |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1205 v->len = ngx_sprintf(p, "%O", r->headers_in.content_length_n) - p; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1206 v->data = p; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1207 v->valid = 1; |
9262
106b3832e7ef
Modified $content_length to match available request body length.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8164
diff
changeset
|
1208 v->no_cacheable = 1; |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1209 v->not_found = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1210 |
7930
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1211 } else if (r->headers_in.chunked) { |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1212 v->not_found = 1; |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1213 v->no_cacheable = 1; |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1214 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1215 } else { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1216 v->not_found = 1; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1217 } |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1218 |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1219 return NGX_OK; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1220 } |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1221 |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1222 |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1223 static ngx_int_t |
573 | 1224 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1225 uintptr_t data) | |
509 | 1226 { |
1811 | 1227 ngx_http_core_srv_conf_t *cscf; |
1228 | |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1229 if (r->headers_in.server.len) { |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1230 v->len = r->headers_in.server.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1231 v->data = r->headers_in.server.data; |
928
a6fe6bedb9e3
fix segfault when $host is used and
Igor Sysoev <igor@sysoev.ru>
parents:
864
diff
changeset
|
1232 |
a6fe6bedb9e3
fix segfault when $host is used and
Igor Sysoev <igor@sysoev.ru>
parents:
864
diff
changeset
|
1233 } else { |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1234 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1235 |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1236 v->len = cscf->server_name.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1237 v->data = cscf->server_name.data; |
509 | 1238 } |
1239 | |
573 | 1240 v->valid = 1; |
1565 | 1241 v->no_cacheable = 0; |
573 | 1242 v->not_found = 0; |
509 | 1243 |
573 | 1244 return NGX_OK; |
499 | 1245 } |
1246 | |
1247 | |
573 | 1248 static ngx_int_t |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1249 ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, |
573 | 1250 ngx_http_variable_value_t *v, uintptr_t data) |
499 | 1251 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1252 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1253 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1254 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1255 #endif |
982 | 1256 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1257 switch (r->connection->sockaddr->sa_family) { |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1258 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1259 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1260 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1261 sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; |
982 | 1262 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1263 v->len = sizeof(struct in6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1264 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1265 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1266 v->not_found = 0; |
3268
c6a40c815d45
use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"
Igor Sysoev <igor@sysoev.ru>
parents:
3144
diff
changeset
|
1267 v->data = sin6->sin6_addr.s6_addr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1268 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1269 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1270 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1271 |
7121
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1272 #if (NGX_HAVE_UNIX_DOMAIN) |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1273 case AF_UNIX: |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1274 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1275 v->len = r->connection->addr_text.len; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1276 v->valid = 1; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1277 v->no_cacheable = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1278 v->not_found = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1279 v->data = r->connection->addr_text.data; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1280 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1281 break; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1282 #endif |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1283 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1284 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1285 sin = (struct sockaddr_in *) r->connection->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1286 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1287 v->len = sizeof(in_addr_t); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1288 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1289 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1290 v->not_found = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1291 v->data = (u_char *) &sin->sin_addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1292 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1293 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1294 } |
982 | 1295 |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1296 return NGX_OK; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1297 } |
982 | 1298 |
1299 | |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1300 static ngx_int_t |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1301 ngx_http_variable_remote_addr(ngx_http_request_t *r, |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1302 ngx_http_variable_value_t *v, uintptr_t data) |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1303 { |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1304 v->len = r->connection->addr_text.len; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1305 v->valid = 1; |
1565 | 1306 v->no_cacheable = 0; |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1307 v->not_found = 0; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1308 v->data = r->connection->addr_text.data; |
499 | 1309 |
573 | 1310 return NGX_OK; |
499 | 1311 } |
1312 | |
1313 | |
573 | 1314 static ngx_int_t |
1315 ngx_http_variable_remote_port(ngx_http_request_t *r, | |
1316 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1317 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1318 ngx_uint_t port; |
509 | 1319 |
573 | 1320 v->len = 0; |
1321 v->valid = 1; | |
1565 | 1322 v->no_cacheable = 0; |
573 | 1323 v->not_found = 0; |
509 | 1324 |
2049 | 1325 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); |
573 | 1326 if (v->data == NULL) { |
1327 return NGX_ERROR; | |
509 | 1328 } |
1329 | |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1330 port = ngx_inet_get_port(r->connection->sockaddr); |
577 | 1331 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1332 if (port > 0 && port < 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1333 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
509 | 1334 } |
1335 | |
573 | 1336 return NGX_OK; |
509 | 1337 } |
1338 | |
1339 | |
573 | 1340 static ngx_int_t |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1341 ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r, |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1342 ngx_http_variable_value_t *v, uintptr_t data) |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1343 { |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1344 ngx_str_t *addr; |
7590
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1345 ngx_proxy_protocol_t *pp; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1346 |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1347 pp = r->connection->proxy_protocol; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1348 if (pp == NULL) { |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1349 v->not_found = 1; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1350 return NGX_OK; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1351 } |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1352 |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1353 addr = (ngx_str_t *) ((char *) pp + data); |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1354 |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1355 v->len = addr->len; |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1356 v->valid = 1; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1357 v->no_cacheable = 0; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1358 v->not_found = 0; |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1359 v->data = addr->data; |
5605
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1360 |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1361 return NGX_OK; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1362 } |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1363 |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1364 |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1365 static ngx_int_t |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1366 ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r, |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1367 ngx_http_variable_value_t *v, uintptr_t data) |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1368 { |
7590
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1369 ngx_uint_t port; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1370 ngx_proxy_protocol_t *pp; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1371 |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1372 pp = r->connection->proxy_protocol; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1373 if (pp == NULL) { |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1374 v->not_found = 1; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1375 return NGX_OK; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1376 } |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1377 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1378 v->len = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1379 v->valid = 1; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1380 v->no_cacheable = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1381 v->not_found = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1382 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1383 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1384 if (v->data == NULL) { |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1385 return NGX_ERROR; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1386 } |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1387 |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1388 port = *(in_port_t *) ((char *) pp + data); |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1389 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1390 if (port > 0 && port < 65536) { |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1391 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1392 } |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1393 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1394 return NGX_OK; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1395 } |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1396 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1397 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1398 static ngx_int_t |
8072
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1399 ngx_http_variable_proxy_protocol_tlv(ngx_http_request_t *r, |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1400 ngx_http_variable_value_t *v, uintptr_t data) |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1401 { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1402 ngx_str_t *name = (ngx_str_t *) data; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1403 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1404 ngx_int_t rc; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1405 ngx_str_t tlv, value; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1406 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1407 tlv.len = name->len - (sizeof("proxy_protocol_tlv_") - 1); |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1408 tlv.data = name->data + sizeof("proxy_protocol_tlv_") - 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1409 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1410 rc = ngx_proxy_protocol_get_tlv(r->connection, &tlv, &value); |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1411 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1412 if (rc == NGX_ERROR) { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1413 return NGX_ERROR; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1414 } |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1415 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1416 if (rc == NGX_DECLINED) { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1417 v->not_found = 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1418 return NGX_OK; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1419 } |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1420 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1421 v->len = value.len; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1422 v->valid = 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1423 v->no_cacheable = 0; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1424 v->not_found = 0; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1425 v->data = value.data; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1426 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1427 return NGX_OK; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1428 } |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1429 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1430 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1431 static ngx_int_t |
573 | 1432 ngx_http_variable_server_addr(ngx_http_request_t *r, |
1433 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1434 { |
1805 | 1435 ngx_str_t s; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1436 u_char addr[NGX_SOCKADDR_STRLEN]; |
499 | 1437 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1438 s.len = NGX_SOCKADDR_STRLEN; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1439 s.data = addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1440 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1441 if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1442 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1443 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1444 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1445 s.data = ngx_pnalloc(r->pool, s.len); |
1805 | 1446 if (s.data == NULL) { |
573 | 1447 return NGX_ERROR; |
509 | 1448 } |
1449 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1450 ngx_memcpy(s.data, addr, s.len); |
509 | 1451 |
1805 | 1452 v->len = s.len; |
573 | 1453 v->valid = 1; |
1565 | 1454 v->no_cacheable = 0; |
573 | 1455 v->not_found = 0; |
1805 | 1456 v->data = s.data; |
499 | 1457 |
573 | 1458 return NGX_OK; |
499 | 1459 } |
1460 | |
1461 | |
573 | 1462 static ngx_int_t |
1463 ngx_http_variable_server_port(ngx_http_request_t *r, | |
1464 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1465 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1466 ngx_uint_t port; |
2533 | 1467 |
1468 v->len = 0; | |
573 | 1469 v->valid = 1; |
1565 | 1470 v->no_cacheable = 0; |
573 | 1471 v->not_found = 0; |
2533 | 1472 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1473 if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) { |
2533 | 1474 return NGX_ERROR; |
1475 } | |
1476 | |
1477 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); | |
1478 if (v->data == NULL) { | |
1479 return NGX_ERROR; | |
1480 } | |
1481 | |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1482 port = ngx_inet_get_port(r->connection->local_sockaddr); |
2533 | 1483 |
1484 if (port > 0 && port < 65536) { | |
1485 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; | |
1486 } | |
509 | 1487 |
573 | 1488 return NGX_OK; |
509 | 1489 } |
1490 | |
1491 | |
573 | 1492 static ngx_int_t |
731 | 1493 ngx_http_variable_scheme(ngx_http_request_t *r, |
1494 ngx_http_variable_value_t *v, uintptr_t data) | |
1495 { | |
1496 #if (NGX_HTTP_SSL) | |
1497 | |
1498 if (r->connection->ssl) { | |
1499 v->len = sizeof("https") - 1; | |
1500 v->valid = 1; | |
1565 | 1501 v->no_cacheable = 0; |
731 | 1502 v->not_found = 0; |
732 | 1503 v->data = (u_char *) "https"; |
731 | 1504 |
1505 return NGX_OK; | |
1506 } | |
1507 | |
1508 #endif | |
1509 | |
1510 v->len = sizeof("http") - 1; | |
1511 v->valid = 1; | |
1565 | 1512 v->no_cacheable = 0; |
731 | 1513 v->not_found = 0; |
732 | 1514 v->data = (u_char *) "http"; |
731 | 1515 |
1516 return NGX_OK; | |
1517 } | |
1518 | |
1519 | |
1520 static ngx_int_t | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1521 ngx_http_variable_https(ngx_http_request_t *r, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1522 ngx_http_variable_value_t *v, uintptr_t data) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1523 { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1524 #if (NGX_HTTP_SSL) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1525 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1526 if (r->connection->ssl) { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1527 v->len = sizeof("on") - 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1528 v->valid = 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1529 v->no_cacheable = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1530 v->not_found = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1531 v->data = (u_char *) "on"; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1532 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1533 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1534 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1535 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1536 #endif |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1537 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1538 *v = ngx_http_variable_null_value; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1539 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1540 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1541 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1542 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1543 |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1544 static void |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1545 ngx_http_variable_set_args(ngx_http_request_t *r, |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1546 ngx_http_variable_value_t *v, uintptr_t data) |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1547 { |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1548 r->args.len = v->len; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1549 r->args.data = v->data; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1550 r->valid_unparsed_uri = 0; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1551 } |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1552 |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1553 |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1554 static ngx_int_t |
1351 | 1555 ngx_http_variable_is_args(ngx_http_request_t *r, |
1556 ngx_http_variable_value_t *v, uintptr_t data) | |
1557 { | |
1558 if (r->args.len == 0) { | |
7053
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1559 *v = ngx_http_variable_null_value; |
1351 | 1560 return NGX_OK; |
1561 } | |
1562 | |
1563 v->len = 1; | |
7053
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1564 v->valid = 1; |
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1565 v->no_cacheable = 0; |
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1566 v->not_found = 0; |
1351 | 1567 v->data = (u_char *) "?"; |
1568 | |
1569 return NGX_OK; | |
1570 } | |
1571 | |
1572 | |
1573 static ngx_int_t | |
573 | 1574 ngx_http_variable_document_root(ngx_http_request_t *r, |
1575 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1576 { |
671 | 1577 ngx_str_t path; |
573 | 1578 ngx_http_core_loc_conf_t *clcf; |
509 | 1579 |
1580 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1581 | |
671 | 1582 if (clcf->root_lengths == NULL) { |
1583 v->len = clcf->root.len; | |
1584 v->valid = 1; | |
1565 | 1585 v->no_cacheable = 0; |
671 | 1586 v->not_found = 0; |
1587 v->data = clcf->root.data; | |
1588 | |
1589 } else { | |
1590 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0, | |
1591 clcf->root_values->elts) | |
1592 == NULL) | |
1593 { | |
1594 return NGX_ERROR; | |
1595 } | |
1596 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1597 if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1598 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1599 { |
671 | 1600 return NGX_ERROR; |
1601 } | |
1602 | |
1603 v->len = path.len; | |
1604 v->valid = 1; | |
1565 | 1605 v->no_cacheable = 0; |
671 | 1606 v->not_found = 0; |
1607 v->data = path.data; | |
1608 } | |
509 | 1609 |
573 | 1610 return NGX_OK; |
509 | 1611 } |
1612 | |
1613 | |
573 | 1614 static ngx_int_t |
2259 | 1615 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1616 ngx_http_variable_value_t *v, uintptr_t data) | |
1617 { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1618 u_char *real; |
2259 | 1619 size_t len; |
1620 ngx_str_t path; | |
1621 ngx_http_core_loc_conf_t *clcf; | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1622 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1623 u_char buffer[NGX_MAX_PATH]; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1624 #endif |
2259 | 1625 |
1626 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1627 | |
1628 if (clcf->root_lengths == NULL) { | |
1629 path = clcf->root; | |
1630 | |
1631 } else { | |
1632 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1, | |
1633 clcf->root_values->elts) | |
1634 == NULL) | |
1635 { | |
1636 return NGX_ERROR; | |
1637 } | |
1638 | |
1639 path.data[path.len - 1] = '\0'; | |
1640 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1641 if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1642 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1643 { |
2259 | 1644 return NGX_ERROR; |
1645 } | |
1646 } | |
1647 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1648 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1649 real = buffer; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1650 #else |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1651 real = NULL; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1652 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1653 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1654 real = ngx_realpath(path.data, real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1655 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1656 if (real == NULL) { |
2259 | 1657 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1658 ngx_realpath_n " \"%s\" failed", path.data); | |
1659 return NGX_ERROR; | |
1660 } | |
1661 | |
1662 len = ngx_strlen(real); | |
1663 | |
1664 v->data = ngx_pnalloc(r->pool, len); | |
1665 if (v->data == NULL) { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1666 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1667 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1668 #endif |
2259 | 1669 return NGX_ERROR; |
1670 } | |
1671 | |
1672 v->len = len; | |
1673 v->valid = 1; | |
1674 v->no_cacheable = 0; | |
1675 v->not_found = 0; | |
1676 | |
1677 ngx_memcpy(v->data, real, len); | |
1678 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1679 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1680 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1681 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1682 |
2259 | 1683 return NGX_OK; |
1684 } | |
1685 | |
1686 | |
1687 static ngx_int_t | |
573 | 1688 ngx_http_variable_request_filename(ngx_http_request_t *r, |
1689 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1690 { |
773 | 1691 size_t root; |
573 | 1692 ngx_str_t path; |
499 | 1693 |
773 | 1694 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
573 | 1695 return NGX_ERROR; |
557 | 1696 } |
509 | 1697 |
557 | 1698 /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */ |
509 | 1699 |
573 | 1700 v->len = path.len - 1; |
1701 v->valid = 1; | |
1565 | 1702 v->no_cacheable = 0; |
573 | 1703 v->not_found = 0; |
1704 v->data = path.data; | |
499 | 1705 |
573 | 1706 return NGX_OK; |
499 | 1707 } |
1708 | |
1709 | |
573 | 1710 static ngx_int_t |
1811 | 1711 ngx_http_variable_server_name(ngx_http_request_t *r, |
1712 ngx_http_variable_value_t *v, uintptr_t data) | |
1713 { | |
1714 ngx_http_core_srv_conf_t *cscf; | |
1715 | |
1716 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1717 | |
1718 v->len = cscf->server_name.len; | |
1719 v->valid = 1; | |
1720 v->no_cacheable = 0; | |
1721 v->not_found = 0; | |
1722 v->data = cscf->server_name.data; | |
1723 | |
1724 return NGX_OK; | |
1725 } | |
1726 | |
1727 | |
1728 static ngx_int_t | |
573 | 1729 ngx_http_variable_request_method(ngx_http_request_t *r, |
1730 ngx_http_variable_value_t *v, uintptr_t data) | |
561 | 1731 { |
647 | 1732 if (r->main->method_name.data) { |
1733 v->len = r->main->method_name.len; | |
573 | 1734 v->valid = 1; |
1565 | 1735 v->no_cacheable = 0; |
573 | 1736 v->not_found = 0; |
647 | 1737 v->data = r->main->method_name.data; |
573 | 1738 |
1739 } else { | |
1740 v->not_found = 1; | |
561 | 1741 } |
1742 | |
573 | 1743 return NGX_OK; |
561 | 1744 } |
1745 | |
1746 | |
573 | 1747 static ngx_int_t |
1748 ngx_http_variable_remote_user(ngx_http_request_t *r, | |
1749 ngx_http_variable_value_t *v, uintptr_t data) | |
539 | 1750 { |
573 | 1751 ngx_int_t rc; |
539 | 1752 |
1753 rc = ngx_http_auth_basic_user(r); | |
1754 | |
1755 if (rc == NGX_DECLINED) { | |
573 | 1756 v->not_found = 1; |
1757 return NGX_OK; | |
539 | 1758 } |
1759 | |
1760 if (rc == NGX_ERROR) { | |
573 | 1761 return NGX_ERROR; |
539 | 1762 } |
1763 | |
573 | 1764 v->len = r->headers_in.user.len; |
1765 v->valid = 1; | |
1565 | 1766 v->no_cacheable = 0; |
573 | 1767 v->not_found = 0; |
1768 v->data = r->headers_in.user.data; | |
571 | 1769 |
573 | 1770 return NGX_OK; |
571 | 1771 } |
1772 | |
1773 | |
611 | 1774 static ngx_int_t |
4886 | 1775 ngx_http_variable_bytes_sent(ngx_http_request_t *r, |
1776 ngx_http_variable_value_t *v, uintptr_t data) | |
1777 { | |
1778 u_char *p; | |
1779 | |
1780 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); | |
1781 if (p == NULL) { | |
1782 return NGX_ERROR; | |
1783 } | |
1784 | |
1785 v->len = ngx_sprintf(p, "%O", r->connection->sent) - p; | |
1786 v->valid = 1; | |
1787 v->no_cacheable = 0; | |
1788 v->not_found = 0; | |
1789 v->data = p; | |
1790 | |
1791 return NGX_OK; | |
1792 } | |
1793 | |
1794 | |
1795 static ngx_int_t | |
611 | 1796 ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
1797 ngx_http_variable_value_t *v, uintptr_t data) | |
1798 { | |
1799 off_t sent; | |
1800 u_char *p; | |
1801 | |
1802 sent = r->connection->sent - r->header_size; | |
1803 | |
1804 if (sent < 0) { | |
1805 sent = 0; | |
1806 } | |
1807 | |
2049 | 1808 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
611 | 1809 if (p == NULL) { |
1810 return NGX_ERROR; | |
1811 } | |
1812 | |
1813 v->len = ngx_sprintf(p, "%O", sent) - p; | |
1814 v->valid = 1; | |
1565 | 1815 v->no_cacheable = 0; |
611 | 1816 v->not_found = 0; |
1817 v->data = p; | |
1818 | |
1819 return NGX_OK; | |
1820 } | |
1821 | |
1822 | |
629 | 1823 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1824 ngx_http_variable_pipe(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1825 ngx_http_variable_value_t *v, uintptr_t data) |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1826 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1827 v->data = (u_char *) (r->pipeline ? "p" : "."); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1828 v->len = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1829 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1830 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1831 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1832 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1833 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1834 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1835 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1836 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1837 static ngx_int_t |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1838 ngx_http_variable_status(ngx_http_request_t *r, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1839 ngx_http_variable_value_t *v, uintptr_t data) |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1840 { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1841 ngx_uint_t status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1842 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1843 v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1844 if (v->data == NULL) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1845 return NGX_ERROR; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1846 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1847 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1848 if (r->err_status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1849 status = r->err_status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1850 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1851 } else if (r->headers_out.status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1852 status = r->headers_out.status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1853 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1854 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1855 status = 9; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1856 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1857 } else { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1858 status = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1859 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1860 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1861 v->len = ngx_sprintf(v->data, "%03ui", status) - v->data; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1862 v->valid = 1; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1863 v->no_cacheable = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1864 v->not_found = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1865 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1866 return NGX_OK; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1867 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1868 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1869 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1870 static ngx_int_t |
641 | 1871 ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
1872 ngx_http_variable_value_t *v, uintptr_t data) | |
1873 { | |
1874 if (r->headers_out.content_type.len) { | |
1875 v->len = r->headers_out.content_type.len; | |
1876 v->valid = 1; | |
1565 | 1877 v->no_cacheable = 0; |
641 | 1878 v->not_found = 0; |
1879 v->data = r->headers_out.content_type.data; | |
1880 | |
1881 } else { | |
1882 v->not_found = 1; | |
1883 } | |
1884 | |
1885 return NGX_OK; | |
1886 } | |
1887 | |
1888 | |
1889 static ngx_int_t | |
1890 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
1891 ngx_http_variable_value_t *v, uintptr_t data) | |
1892 { | |
1893 u_char *p; | |
1894 | |
1895 if (r->headers_out.content_length) { | |
1896 v->len = r->headers_out.content_length->value.len; | |
1897 v->valid = 1; | |
1565 | 1898 v->no_cacheable = 0; |
641 | 1899 v->not_found = 0; |
1900 v->data = r->headers_out.content_length->value.data; | |
1901 | |
1902 return NGX_OK; | |
1903 } | |
1904 | |
1905 if (r->headers_out.content_length_n >= 0) { | |
2049 | 1906 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
641 | 1907 if (p == NULL) { |
1908 return NGX_ERROR; | |
1909 } | |
1910 | |
1911 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
1912 v->valid = 1; | |
1565 | 1913 v->no_cacheable = 0; |
641 | 1914 v->not_found = 0; |
1915 v->data = p; | |
1916 | |
1917 return NGX_OK; | |
1918 } | |
1919 | |
1920 v->not_found = 1; | |
1921 | |
1922 return NGX_OK; | |
1923 } | |
1924 | |
1925 | |
1926 static ngx_int_t | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1927 ngx_http_variable_sent_location(ngx_http_request_t *r, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1928 ngx_http_variable_value_t *v, uintptr_t data) |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1929 { |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1930 ngx_str_t name; |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1931 |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1932 if (r->headers_out.location) { |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1933 v->len = r->headers_out.location->value.len; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1934 v->valid = 1; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1935 v->no_cacheable = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1936 v->not_found = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1937 v->data = r->headers_out.location->value.data; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1938 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1939 return NGX_OK; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1940 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1941 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
1942 ngx_str_set(&name, "sent_http_location"); |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1943 |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1944 return ngx_http_variable_unknown_header(r, v, &name, |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1945 &r->headers_out.headers.part, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1946 sizeof("sent_http_") - 1); |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1947 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1948 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1949 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1950 static ngx_int_t |
641 | 1951 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
1952 ngx_http_variable_value_t *v, uintptr_t data) | |
1953 { | |
1954 u_char *p; | |
1955 | |
1956 if (r->headers_out.last_modified) { | |
1957 v->len = r->headers_out.last_modified->value.len; | |
1958 v->valid = 1; | |
1565 | 1959 v->no_cacheable = 0; |
641 | 1960 v->not_found = 0; |
1961 v->data = r->headers_out.last_modified->value.data; | |
1962 | |
1963 return NGX_OK; | |
1964 } | |
1965 | |
1966 if (r->headers_out.last_modified_time >= 0) { | |
5434
c21e341c51cb
Removed extra allocation for $sent_http_last_modified.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5361
diff
changeset
|
1967 p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
641 | 1968 if (p == NULL) { |
1969 return NGX_ERROR; | |
1970 } | |
1971 | |
1972 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
1973 v->valid = 1; | |
1565 | 1974 v->no_cacheable = 0; |
641 | 1975 v->not_found = 0; |
1976 v->data = p; | |
1977 | |
1978 return NGX_OK; | |
1979 } | |
1980 | |
1981 v->not_found = 1; | |
1982 | |
1983 return NGX_OK; | |
1984 } | |
1985 | |
1986 | |
1987 static ngx_int_t | |
1988 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
1989 ngx_http_variable_value_t *v, uintptr_t data) | |
1990 { | |
1991 size_t len; | |
1992 char *p; | |
1993 | |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1994 if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) { |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1995 len = sizeof("upgrade") - 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1996 p = "upgrade"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1997 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1998 } else if (r->keepalive) { |
641 | 1999 len = sizeof("keep-alive") - 1; |
2000 p = "keep-alive"; | |
2001 | |
2002 } else { | |
2003 len = sizeof("close") - 1; | |
2004 p = "close"; | |
2005 } | |
2006 | |
2007 v->len = len; | |
2008 v->valid = 1; | |
1565 | 2009 v->no_cacheable = 0; |
641 | 2010 v->not_found = 0; |
2011 v->data = (u_char *) p; | |
2012 | |
2013 return NGX_OK; | |
2014 } | |
2015 | |
2016 | |
2017 static ngx_int_t | |
2018 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
2019 ngx_http_variable_value_t *v, uintptr_t data) | |
2020 { | |
2021 u_char *p; | |
2022 ngx_http_core_loc_conf_t *clcf; | |
2023 | |
2024 if (r->keepalive) { | |
2025 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
2026 | |
2027 if (clcf->keepalive_header) { | |
2028 | |
2049 | 2029 p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); |
641 | 2030 if (p == NULL) { |
2031 return NGX_ERROR; | |
2032 } | |
2033 | |
2034 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
2035 v->valid = 1; | |
1565 | 2036 v->no_cacheable = 0; |
641 | 2037 v->not_found = 0; |
2038 v->data = p; | |
2039 | |
2040 return NGX_OK; | |
2041 } | |
2042 } | |
2043 | |
2044 v->not_found = 1; | |
2045 | |
2046 return NGX_OK; | |
2047 } | |
2048 | |
2049 | |
2050 static ngx_int_t | |
2051 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
2052 ngx_http_variable_value_t *v, uintptr_t data) | |
2053 { | |
2054 if (r->chunked) { | |
2055 v->len = sizeof("chunked") - 1; | |
2056 v->valid = 1; | |
1565 | 2057 v->no_cacheable = 0; |
641 | 2058 v->not_found = 0; |
2059 v->data = (u_char *) "chunked"; | |
2060 | |
2061 } else { | |
2062 v->not_found = 1; | |
2063 } | |
2064 | |
2065 return NGX_OK; | |
2066 } | |
2067 | |
2068 | |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2069 static void |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2070 ngx_http_variable_set_limit_rate(ngx_http_request_t *r, |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2071 ngx_http_variable_value_t *v, uintptr_t data) |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2072 { |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2073 ssize_t s; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2074 ngx_str_t val; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2075 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2076 val.len = v->len; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2077 val.data = v->data; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2078 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2079 s = ngx_parse_size(&val); |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2080 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2081 if (s == NGX_ERROR) { |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2082 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2083 "invalid $limit_rate \"%V\"", &val); |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2084 return; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2085 } |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2086 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2087 r->limit_rate = s; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2088 r->limit_rate_set = 1; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2089 } |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2090 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2091 |
641 | 2092 static ngx_int_t |
629 | 2093 ngx_http_variable_request_completion(ngx_http_request_t *r, |
2094 ngx_http_variable_value_t *v, uintptr_t data) | |
2095 { | |
2096 if (r->request_complete) { | |
2097 v->len = 2; | |
2098 v->valid = 1; | |
1565 | 2099 v->no_cacheable = 0; |
629 | 2100 v->not_found = 0; |
2101 v->data = (u_char *) "OK"; | |
2102 | |
2103 return NGX_OK; | |
2104 } | |
2105 | |
7053
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
2106 *v = ngx_http_variable_null_value; |
629 | 2107 |
2108 return NGX_OK; | |
2109 } | |
2110 | |
2111 | |
759 | 2112 static ngx_int_t |
2844 | 2113 ngx_http_variable_request_body(ngx_http_request_t *r, |
2114 ngx_http_variable_value_t *v, uintptr_t data) | |
2115 { | |
2116 u_char *p; | |
2117 size_t len; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2118 ngx_buf_t *buf; |
2844 | 2119 ngx_chain_t *cl; |
2120 | |
2878
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2121 if (r->request_body == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2122 || r->request_body->bufs == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2123 || r->request_body->temp_file) |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2124 { |
2844 | 2125 v->not_found = 1; |
2126 | |
2127 return NGX_OK; | |
2128 } | |
2129 | |
2130 cl = r->request_body->bufs; | |
2131 buf = cl->buf; | |
2132 | |
2133 if (cl->next == NULL) { | |
2134 v->len = buf->last - buf->pos; | |
2135 v->valid = 1; | |
2136 v->no_cacheable = 0; | |
2137 v->not_found = 0; | |
2138 v->data = buf->pos; | |
2139 | |
2140 return NGX_OK; | |
2141 } | |
2142 | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2143 len = buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2144 cl = cl->next; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2145 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2146 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2147 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2148 len += buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2149 } |
2844 | 2150 |
2151 p = ngx_pnalloc(r->pool, len); | |
2152 if (p == NULL) { | |
2153 return NGX_ERROR; | |
2154 } | |
2155 | |
2156 v->data = p; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2157 cl = r->request_body->bufs; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2158 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2159 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2160 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2161 p = ngx_cpymem(p, buf->pos, buf->last - buf->pos); |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2162 } |
2844 | 2163 |
2164 v->len = len; | |
2165 v->valid = 1; | |
2166 v->no_cacheable = 0; | |
2167 v->not_found = 0; | |
2168 | |
2169 return NGX_OK; | |
2170 } | |
2171 | |
2172 | |
2173 static ngx_int_t | |
759 | 2174 ngx_http_variable_request_body_file(ngx_http_request_t *r, |
2175 ngx_http_variable_value_t *v, uintptr_t data) | |
2176 { | |
2177 if (r->request_body == NULL || r->request_body->temp_file == NULL) { | |
763
0b0f3d4854c0
variable should not be found if no request body file
Igor Sysoev <igor@sysoev.ru>
parents:
759
diff
changeset
|
2178 v->not_found = 1; |
759 | 2179 |
2180 return NGX_OK; | |
2181 } | |
2182 | |
2183 v->len = r->request_body->temp_file->file.name.len; | |
2184 v->valid = 1; | |
1565 | 2185 v->no_cacheable = 0; |
759 | 2186 v->not_found = 0; |
2187 v->data = r->request_body->temp_file->file.name.data; | |
2188 | |
2189 return NGX_OK; | |
2190 } | |
2191 | |
2192 | |
1329 | 2193 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2194 ngx_http_variable_request_length(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2195 ngx_http_variable_value_t *v, uintptr_t data) |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2196 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2197 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2198 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2199 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2200 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2201 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2202 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2203 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2204 v->len = ngx_sprintf(p, "%O", r->request_length) - p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2205 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2206 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2207 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2208 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2209 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2210 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2211 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2212 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2213 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2214 static ngx_int_t |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2215 ngx_http_variable_request_time(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2216 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2217 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2218 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2219 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2220 ngx_msec_int_t ms; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2221 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2222 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2223 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2224 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2225 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2226 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2227 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2228 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2229 ms = (ngx_msec_int_t) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2230 ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2231 ms = ngx_max(ms, 0); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2232 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5327
diff
changeset
|
2233 v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p; |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2234 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2235 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2236 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2237 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2238 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2239 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2240 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2241 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2242 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2243 static ngx_int_t |
6531 | 2244 ngx_http_variable_request_id(ngx_http_request_t *r, |
2245 ngx_http_variable_value_t *v, uintptr_t data) | |
2246 { | |
2247 u_char *id; | |
2248 | |
2249 #if (NGX_OPENSSL) | |
2250 u_char random_bytes[16]; | |
2251 #endif | |
2252 | |
2253 id = ngx_pnalloc(r->pool, 32); | |
2254 if (id == NULL) { | |
2255 return NGX_ERROR; | |
2256 } | |
2257 | |
2258 v->valid = 1; | |
2259 v->no_cacheable = 0; | |
2260 v->not_found = 0; | |
2261 | |
2262 v->len = 32; | |
2263 v->data = id; | |
2264 | |
2265 #if (NGX_OPENSSL) | |
2266 | |
2267 if (RAND_bytes(random_bytes, 16) == 1) { | |
2268 ngx_hex_dump(id, random_bytes, 16); | |
2269 return NGX_OK; | |
2270 } | |
2271 | |
2272 ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0, "RAND_bytes() failed"); | |
2273 | |
2274 #endif | |
2275 | |
2276 ngx_sprintf(id, "%08xD%08xD%08xD%08xD", | |
2277 (uint32_t) ngx_random(), (uint32_t) ngx_random(), | |
2278 (uint32_t) ngx_random(), (uint32_t) ngx_random()); | |
2279 | |
2280 return NGX_OK; | |
2281 } | |
2282 | |
2283 | |
2284 static ngx_int_t | |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2285 ngx_http_variable_connection(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2286 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2287 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2288 u_char *p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2289 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2290 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2291 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2292 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2293 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2294 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2295 v->len = ngx_sprintf(p, "%uA", r->connection->number) - p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2296 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2297 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2298 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2299 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2300 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2301 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2302 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2303 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2304 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2305 static ngx_int_t |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2306 ngx_http_variable_connection_requests(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2307 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2308 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2309 u_char *p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2310 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2311 p = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2312 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2313 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2314 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2315 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2316 v->len = ngx_sprintf(p, "%ui", r->connection->requests) - p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2317 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2318 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2319 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2320 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2321 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2322 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2323 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2324 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2325 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2326 static ngx_int_t |
7821
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2327 ngx_http_variable_connection_time(ngx_http_request_t *r, |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2328 ngx_http_variable_value_t *v, uintptr_t data) |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2329 { |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2330 u_char *p; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2331 ngx_msec_int_t ms; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2332 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2333 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2334 if (p == NULL) { |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2335 return NGX_ERROR; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2336 } |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2337 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2338 ms = ngx_current_msec - r->connection->start_time; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2339 ms = ngx_max(ms, 0); |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2340 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2341 v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2342 v->valid = 1; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2343 v->no_cacheable = 0; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2344 v->not_found = 0; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2345 v->data = p; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2346 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2347 return NGX_OK; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2348 } |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2349 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2350 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2351 static ngx_int_t |
1329 | 2352 ngx_http_variable_nginx_version(ngx_http_request_t *r, |
2353 ngx_http_variable_value_t *v, uintptr_t data) | |
2354 { | |
2355 v->len = sizeof(NGINX_VERSION) - 1; | |
2356 v->valid = 1; | |
1565 | 2357 v->no_cacheable = 0; |
1329 | 2358 v->not_found = 0; |
2359 v->data = (u_char *) NGINX_VERSION; | |
2360 | |
2361 return NGX_OK; | |
2362 } | |
2363 | |
2364 | |
2011 | 2365 static ngx_int_t |
2366 ngx_http_variable_hostname(ngx_http_request_t *r, | |
2367 ngx_http_variable_value_t *v, uintptr_t data) | |
2368 { | |
2369 v->len = ngx_cycle->hostname.len; | |
2370 v->valid = 1; | |
2371 v->no_cacheable = 0; | |
2372 v->not_found = 0; | |
2373 v->data = ngx_cycle->hostname.data; | |
2374 | |
2375 return NGX_OK; | |
2376 } | |
2377 | |
2378 | |
2249 | 2379 static ngx_int_t |
2380 ngx_http_variable_pid(ngx_http_request_t *r, | |
2381 ngx_http_variable_value_t *v, uintptr_t data) | |
2382 { | |
2383 u_char *p; | |
2384 | |
2385 p = ngx_pnalloc(r->pool, NGX_INT64_LEN); | |
2386 if (p == NULL) { | |
2387 return NGX_ERROR; | |
2388 } | |
2389 | |
2390 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; | |
2391 v->valid = 1; | |
2392 v->no_cacheable = 0; | |
2393 v->not_found = 0; | |
2394 v->data = p; | |
2395 | |
2396 return NGX_OK; | |
2397 } | |
2398 | |
2399 | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2400 static ngx_int_t |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2401 ngx_http_variable_msec(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2402 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2403 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2404 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2405 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2406 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2407 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2408 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2409 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2410 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2411 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2412 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2413 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2414 v->len = ngx_sprintf(p, "%T.%03M", tp->sec, tp->msec) - p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2415 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2416 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2417 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2418 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2419 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2420 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2421 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2422 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2423 |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2424 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2425 ngx_http_variable_time_iso8601(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2426 ngx_http_variable_value_t *v, uintptr_t data) |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2427 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2428 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2429 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2430 p = ngx_pnalloc(r->pool, ngx_cached_http_log_iso8601.len); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2431 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2432 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2433 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2434 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2435 ngx_memcpy(p, ngx_cached_http_log_iso8601.data, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2436 ngx_cached_http_log_iso8601.len); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2437 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2438 v->len = ngx_cached_http_log_iso8601.len; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2439 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2440 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2441 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2442 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2443 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2444 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2445 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2446 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2447 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2448 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2449 ngx_http_variable_time_local(ngx_http_request_t *r, |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2450 ngx_http_variable_value_t *v, uintptr_t data) |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2451 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2452 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2453 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2454 p = ngx_pnalloc(r->pool, ngx_cached_http_log_time.len); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2455 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2456 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2457 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2458 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2459 ngx_memcpy(p, ngx_cached_http_log_time.data, ngx_cached_http_log_time.len); |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2460 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2461 v->len = ngx_cached_http_log_time.len; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2462 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2463 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2464 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2465 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2466 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2467 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2468 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2469 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2470 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2471 void * |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2472 ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_str_t *match) |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2473 { |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2474 void *value; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2475 u_char *low; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2476 size_t len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2477 ngx_uint_t key; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2478 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2479 len = match->len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2480 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2481 if (len) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2482 low = ngx_pnalloc(r->pool, len); |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2483 if (low == NULL) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2484 return NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2485 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2486 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2487 } else { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2488 low = NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2489 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2490 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2491 key = ngx_hash_strlow(low, match->data, len); |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2492 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2493 value = ngx_hash_find_combined(&map->hash, key, low, len); |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2494 if (value) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2495 return value; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2496 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2497 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2498 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2499 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2500 if (len && map->nregex) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2501 ngx_int_t n; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2502 ngx_uint_t i; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2503 ngx_http_map_regex_t *reg; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2504 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2505 reg = map->regex; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2506 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2507 for (i = 0; i < map->nregex; i++) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2508 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2509 n = ngx_http_regex_exec(r, reg[i].regex, match); |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2510 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2511 if (n == NGX_OK) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2512 return reg[i].value; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2513 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2514 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2515 if (n == NGX_DECLINED) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2516 continue; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2517 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2518 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2519 /* NGX_ERROR */ |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2520 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2521 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2522 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2523 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2524 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2525 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2526 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2527 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2528 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2529 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2530 |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2531 #if (NGX_PCRE) |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2532 |
3325 | 2533 static ngx_int_t |
2534 ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
2535 uintptr_t data) | |
2536 { | |
2537 v->not_found = 1; | |
2538 return NGX_OK; | |
2539 } | |
2540 | |
2541 | |
2542 ngx_http_regex_t * | |
2543 ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
2544 { | |
2545 u_char *p; | |
2546 size_t size; | |
2547 ngx_str_t name; | |
2548 ngx_uint_t i, n; | |
2549 ngx_http_variable_t *v; | |
2550 ngx_http_regex_t *re; | |
2551 ngx_http_regex_variable_t *rv; | |
2552 ngx_http_core_main_conf_t *cmcf; | |
2553 | |
2554 rc->pool = cf->pool; | |
2555 | |
2556 if (ngx_regex_compile(rc) != NGX_OK) { | |
2557 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
2558 return NULL; | |
2559 } | |
2560 | |
2561 re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t)); | |
2562 if (re == NULL) { | |
2563 return NULL; | |
2564 } | |
2565 | |
2566 re->regex = rc->regex; | |
2567 re->ncaptures = rc->captures; | |
5204
a64c8a5da336
PCRE: retain input pattern for all regular expressions.
Piotr Sikora <piotr@cloudflare.com>
parents:
5084
diff
changeset
|
2568 re->name = rc->pattern; |
3325 | 2569 |
2570 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2571 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
2572 | |
2573 n = (ngx_uint_t) rc->named_captures; | |
2574 | |
2575 if (n == 0) { | |
2576 return re; | |
2577 } | |
2578 | |
2579 rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t)); | |
2580 if (rv == NULL) { | |
2581 return NULL; | |
2582 } | |
2583 | |
2584 re->variables = rv; | |
2585 re->nvariables = n; | |
2586 | |
2587 size = rc->name_size; | |
2588 p = rc->names; | |
2589 | |
2590 for (i = 0; i < n; i++) { | |
2591 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
2592 | |
2593 name.data = &p[2]; | |
2594 name.len = ngx_strlen(name.data); | |
2595 | |
2596 v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); | |
2597 if (v == NULL) { | |
2598 return NULL; | |
2599 } | |
2600 | |
2601 rv[i].index = ngx_http_get_variable_index(cf, &name); | |
2602 if (rv[i].index == NGX_ERROR) { | |
2603 return NULL; | |
2604 } | |
2605 | |
2606 v->get_handler = ngx_http_variable_not_found; | |
2607 | |
3409
bb79608169eb
named captures worked for two names only
Igor Sysoev <igor@sysoev.ru>
parents:
3356
diff
changeset
|
2608 p += size; |
3325 | 2609 } |
2610 | |
2611 return re; | |
2612 } | |
2613 | |
2614 | |
2615 ngx_int_t | |
2616 ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s) | |
2617 { | |
2618 ngx_int_t rc, index; | |
2619 ngx_uint_t i, n, len; | |
2620 ngx_http_variable_value_t *vv; | |
2621 ngx_http_core_main_conf_t *cmcf; | |
2622 | |
2623 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
2624 | |
2625 if (re->ncaptures) { | |
3345
d8228f0b5113
evaluate maximum captures size on configuration phase
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
2626 len = cmcf->ncaptures; |
3325 | 2627 |
7427
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2628 if (r->captures == NULL || r->realloc_captures) { |
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2629 r->realloc_captures = 0; |
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2630 |
3325 | 2631 r->captures = ngx_palloc(r->pool, len * sizeof(int)); |
2632 if (r->captures == NULL) { | |
2633 return NGX_ERROR; | |
2634 } | |
2635 } | |
2636 | |
2637 } else { | |
2638 len = 0; | |
2639 } | |
2640 | |
2641 rc = ngx_regex_exec(re->regex, s, r->captures, len); | |
2642 | |
2643 if (rc == NGX_REGEX_NO_MATCHED) { | |
2644 return NGX_DECLINED; | |
2645 } | |
2646 | |
2647 if (rc < 0) { | |
2648 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
2649 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
2650 rc, s, &re->name); | |
2651 return NGX_ERROR; | |
2652 } | |
2653 | |
2654 for (i = 0; i < re->nvariables; i++) { | |
2655 | |
2656 n = re->variables[i].capture; | |
2657 index = re->variables[i].index; | |
2658 vv = &r->variables[index]; | |
2659 | |
2660 vv->len = r->captures[n + 1] - r->captures[n]; | |
2661 vv->valid = 1; | |
2662 vv->no_cacheable = 0; | |
2663 vv->not_found = 0; | |
2664 vv->data = &s->data[r->captures[n]]; | |
2665 | |
2666 #if (NGX_DEBUG) | |
2667 { | |
2668 ngx_http_variable_t *v; | |
2669 | |
2670 v = cmcf->variables.elts; | |
2671 | |
6478
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6263
diff
changeset
|
2672 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6263
diff
changeset
|
2673 "http regex set $%V to \"%v\"", &v[index].name, vv); |
3325 | 2674 } |
2675 #endif | |
2676 } | |
2677 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2678 r->ncaptures = rc * 2; |
3325 | 2679 r->captures_data = s->data; |
2680 | |
2681 return NGX_OK; | |
2682 } | |
2683 | |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2684 #endif |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2685 |
3325 | 2686 |
499 | 2687 ngx_int_t |
509 | 2688 ngx_http_variables_add_core_vars(ngx_conf_t *cf) |
499 | 2689 { |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2690 ngx_http_variable_t *cv, *v; |
501 | 2691 ngx_http_core_main_conf_t *cmcf; |
499 | 2692 |
509 | 2693 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2694 | |
611 | 2695 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, |
2696 sizeof(ngx_hash_keys_arrays_t)); | |
2697 if (cmcf->variables_keys == NULL) { | |
2698 return NGX_ERROR; | |
2699 } | |
2700 | |
2701 cmcf->variables_keys->pool = cf->pool; | |
2702 cmcf->variables_keys->temp_pool = cf->pool; | |
2703 | |
2704 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
2705 != NGX_OK) | |
509 | 2706 { |
499 | 2707 return NGX_ERROR; |
2708 } | |
2709 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2710 if (ngx_array_init(&cmcf->prefix_variables, cf->pool, 8, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2711 sizeof(ngx_http_variable_t)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2712 != NGX_OK) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2713 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2714 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2715 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2716 |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2717 for (cv = ngx_http_core_variables; cv->name.len; cv++) { |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2718 v = ngx_http_add_variable(cf, &cv->name, cv->flags); |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2719 if (v == NULL) { |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2720 return NGX_ERROR; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2721 } |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2722 |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2723 *v = *cv; |
499 | 2724 } |
2725 | |
2726 return NGX_OK; | |
2727 } | |
509 | 2728 |
2729 | |
2730 ngx_int_t | |
2731 ngx_http_variables_init_vars(ngx_conf_t *cf) | |
2732 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2733 size_t len; |
509 | 2734 ngx_uint_t i, n; |
611 | 2735 ngx_hash_key_t *key; |
2736 ngx_hash_init_t hash; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2737 ngx_http_variable_t *v, *av, *pv; |
509 | 2738 ngx_http_core_main_conf_t *cmcf; |
2739 | |
2740 /* set the handlers for the indexed http variables */ | |
2741 | |
2742 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2743 | |
2744 v = cmcf->variables.elts; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2745 pv = cmcf->prefix_variables.elts; |
611 | 2746 key = cmcf->variables_keys->keys.elts; |
509 | 2747 |
2748 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2749 | |
611 | 2750 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
509 | 2751 |
1191
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2752 av = key[n].value; |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2753 |
5815
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2754 if (v[i].name.len == key[n].key.len |
611 | 2755 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) |
509 | 2756 == 0) |
2757 { | |
637 | 2758 v[i].get_handler = av->get_handler; |
611 | 2759 v[i].data = av->data; |
527 | 2760 |
611 | 2761 av->flags |= NGX_HTTP_VAR_INDEXED; |
2762 v[i].flags = av->flags; | |
509 | 2763 |
611 | 2764 av->index = i; |
533 | 2765 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2766 if (av->get_handler == NULL |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2767 || (av->flags & NGX_HTTP_VAR_WEAK)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2768 { |
5815
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2769 break; |
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2770 } |
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2771 |
509 | 2772 goto next; |
2773 } | |
2774 } | |
2775 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2776 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2777 av = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2778 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2779 for (n = 0; n < cmcf->prefix_variables.nelts; n++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2780 if (v[i].name.len >= pv[n].name.len && v[i].name.len > len |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2781 && ngx_strncmp(v[i].name.data, pv[n].name.data, pv[n].name.len) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2782 == 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2783 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2784 av = &pv[n]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2785 len = pv[n].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2786 } |
1162 | 2787 } |
2788 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2789 if (av) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2790 v[i].get_handler = av->get_handler; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5605
diff
changeset
|
2791 v[i].data = (uintptr_t) &v[i].name; |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2792 v[i].flags = av->flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2793 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2794 goto next; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5605
diff
changeset
|
2795 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5605
diff
changeset
|
2796 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2797 if (v[i].get_handler == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2798 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2799 "unknown \"%V\" variable", &v[i].name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2800 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2801 return NGX_ERROR; |
2137 | 2802 } |
2803 | |
509 | 2804 next: |
2805 continue; | |
2806 } | |
2807 | |
2808 | |
611 | 2809 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
2810 av = key[n].value; | |
2811 | |
2812 if (av->flags & NGX_HTTP_VAR_NOHASH) { | |
2813 key[n].key.data = NULL; | |
583 | 2814 } |
2815 } | |
2816 | |
2817 | |
611 | 2818 hash.hash = &cmcf->variables_hash; |
2819 hash.key = ngx_hash_key; | |
2820 hash.max_size = cmcf->variables_hash_max_size; | |
2821 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
2822 hash.name = "variables_hash"; | |
2823 hash.pool = cf->pool; | |
2824 hash.temp_pool = NULL; | |
509 | 2825 |
611 | 2826 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, |
2827 cmcf->variables_keys->keys.nelts) | |
581 | 2828 != NGX_OK) |
509 | 2829 { |
2830 return NGX_ERROR; | |
2831 } | |
2832 | |
611 | 2833 cmcf->variables_keys = NULL; |
509 | 2834 |
2835 return NGX_OK; | |
2836 } |