Mercurial > hg > nginx
annotate src/http/ngx_http_variables.c @ 8164:b71e69247483
Variables: avoid possible buffer overrun with some "$sent_http_*".
The existing logic to evaluate multi header "$sent_http_*" variables,
such as $sent_http_cache_control, as previously introduced in 1.23.0,
doesn't take into account that one or more elements can be cleared,
yet still present in a linked list, pointed to by the next field.
Such elements don't contribute to the resulting variable length, an
attempt to append a separator for them ends up in out of bounds write.
This is not possible with standard modules, though at least one third
party module is known to override multi header values this way, so it
makes sense to harden the logic.
The fix restores a generic boundary check.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Mon, 01 May 2023 19:16:05 +0400 |
parents | cca4c8a715de |
children | 106b3832e7ef |
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 #if (NGX_SUPPRESS_WARN) |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
936 len = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
937 #endif |
499 | 938 |
939 header = part->elts; | |
940 | |
941 for (i = 0; /* void */ ; i++) { | |
942 | |
943 if (i >= part->nelts) { | |
944 if (part->next == NULL) { | |
945 break; | |
946 } | |
947 | |
948 part = part->next; | |
949 header = part->elts; | |
950 i = 0; | |
951 } | |
952 | |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
953 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
|
954 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
955 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
956 |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
957 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
|
958 continue; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
959 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
960 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
961 for (n = 0; n < var->len - prefix; n++) { |
499 | 962 ch = header[i].key.data[n]; |
963 | |
509 | 964 if (ch >= 'A' && ch <= 'Z') { |
965 ch |= 0x20; | |
499 | 966 |
967 } else if (ch == '-') { | |
968 ch = '_'; | |
969 } | |
970 | |
577 | 971 if (var->data[n + prefix] != ch) { |
499 | 972 break; |
973 } | |
974 } | |
975 | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
976 if (n != var->len - prefix) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
977 continue; |
499 | 978 } |
8023
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 len += header[i].value.len + 2; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
981 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
982 *ph = &header[i]; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
983 ph = &header[i].next; |
499 | 984 } |
985 | |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
986 *ph = NULL; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
987 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
988 if (h == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
989 v->not_found = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
990 return NGX_OK; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
991 } |
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 len -= 2; |
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 if (h->next == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
996 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
997 v->len = h->value.len; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
998 v->valid = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
999 v->no_cacheable = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1000 v->not_found = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1001 v->data = h->value.data; |
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 return NGX_OK; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1004 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1005 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1006 p = ngx_pnalloc(r->pool, len); |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1007 if (p == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1008 return NGX_ERROR; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1009 } |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1010 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1011 v->len = len; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1012 v->valid = 1; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1013 v->no_cacheable = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1014 v->not_found = 0; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1015 v->data = p; |
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 for ( ;; ) { |
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 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
|
1020 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1021 if (h->next == NULL) { |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1022 break; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1023 } |
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 *p++ = ','; *p++ = ' '; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1026 |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1027 h = h->next; |
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1028 } |
573 | 1029 |
1030 return NGX_OK; | |
509 | 1031 } |
1032 | |
1033 | |
573 | 1034 static ngx_int_t |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1035 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
|
1036 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
|
1037 { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1038 u_char *p, *s; |
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 s = r->request_line.data; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1041 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1042 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1043 s = r->request_start; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1044 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1045 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1046 v->not_found = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1047 return NGX_OK; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1048 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1049 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1050 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
|
1051 if (*p == CR || *p == LF) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1052 break; |
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 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1055 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1056 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
|
1057 r->request_line.data = s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1058 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1059 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1060 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
|
1061 v->valid = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1062 v->no_cacheable = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1063 v->not_found = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1064 v->data = s; |
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 return NGX_OK; |
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 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1069 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
1070 static ngx_int_t |
2307 | 1071 ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1072 uintptr_t data) | |
1073 { | |
1074 ngx_str_t *name = (ngx_str_t *) data; | |
1075 | |
1076 ngx_str_t cookie, s; | |
1077 | |
1078 s.len = name->len - (sizeof("cookie_") - 1); | |
1079 s.data = name->data + sizeof("cookie_") - 1; | |
1080 | |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8023
diff
changeset
|
1081 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
|
1082 == NULL) |
2307 | 1083 { |
1084 v->not_found = 1; | |
1085 return NGX_OK; | |
1086 } | |
1087 | |
1088 v->len = cookie.len; | |
1089 v->valid = 1; | |
1090 v->no_cacheable = 0; | |
1091 v->not_found = 0; | |
1092 v->data = cookie.data; | |
1093 | |
1094 return NGX_OK; | |
1095 } | |
1096 | |
1097 | |
1098 static ngx_int_t | |
2137 | 1099 ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1100 uintptr_t data) | |
1101 { | |
1102 ngx_str_t *name = (ngx_str_t *) data; | |
1103 | |
2415 | 1104 u_char *arg; |
1105 size_t len; | |
1106 ngx_str_t value; | |
2137 | 1107 |
2415 | 1108 len = name->len - (sizeof("arg_") - 1); |
1109 arg = name->data + sizeof("arg_") - 1; | |
1110 | |
7648
028b16e2798f
Variables: fixed buffer over-read when evaluating "$arg_".
Sergey Kandaurov <pluknet@nginx.com>
parents:
7591
diff
changeset
|
1111 if (len == 0 || ngx_http_arg(r, arg, len, &value) != NGX_OK) { |
2137 | 1112 v->not_found = 1; |
1113 return NGX_OK; | |
1114 } | |
1115 | |
2415 | 1116 v->data = value.data; |
1117 v->len = value.len; | |
1118 v->valid = 1; | |
1119 v->no_cacheable = 0; | |
1120 v->not_found = 0; | |
2137 | 1121 |
1122 return NGX_OK; | |
1123 } | |
1124 | |
1125 | |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1126 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1127 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1128 static ngx_int_t |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1129 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
|
1130 uintptr_t data) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1131 { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1132 struct tcp_info ti; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1133 socklen_t len; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1134 uint32_t value; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1135 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1136 len = sizeof(struct tcp_info); |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1137 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
|
1138 v->not_found = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1139 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1140 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1141 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1142 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
|
1143 if (v->data == NULL) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1144 return NGX_ERROR; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1145 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1146 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1147 switch (data) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1148 case 0: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1149 value = ti.tcpi_rtt; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1150 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1151 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1152 case 1: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1153 value = ti.tcpi_rttvar; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1154 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1155 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1156 case 2: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1157 value = ti.tcpi_snd_cwnd; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1158 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1159 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1160 case 3: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1161 value = ti.tcpi_rcv_space; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1162 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1163 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1164 /* suppress warning */ |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1165 default: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1166 value = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1167 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1168 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1169 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1170 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
|
1171 v->valid = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1172 v->no_cacheable = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1173 v->not_found = 0; |
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 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1176 } |
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 #endif |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1179 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
1180 |
2137 | 1181 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
|
1182 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
|
1183 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
|
1184 { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1185 u_char *p; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1186 |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1187 if (r->headers_in.content_length) { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1188 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
|
1189 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
|
1190 v->valid = 1; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1191 v->no_cacheable = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1192 v->not_found = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1193 |
6050
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1194 } else if (r->reading_body) { |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1195 v->not_found = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1196 v->no_cacheable = 1; |
a08fad30aeac
Request body: unbuffered reading.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5815
diff
changeset
|
1197 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1198 } 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
|
1199 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
|
1200 if (p == NULL) { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1201 return NGX_ERROR; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1202 } |
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 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
|
1205 v->data = p; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1206 v->valid = 1; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1207 v->no_cacheable = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1208 v->not_found = 0; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1209 |
7930
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1210 } else if (r->headers_in.chunked) { |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1211 v->not_found = 1; |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1212 v->no_cacheable = 1; |
ae7c767aa491
Fixed $content_length cacheability with chunked (ticket #2252).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7821
diff
changeset
|
1213 |
4928
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1214 } else { |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1215 v->not_found = 1; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1216 } |
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 return NGX_OK; |
ec7d97006a30
Request body: $content_length variable to honor real body size.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4921
diff
changeset
|
1219 } |
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 static ngx_int_t |
573 | 1223 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
1224 uintptr_t data) | |
509 | 1225 { |
1811 | 1226 ngx_http_core_srv_conf_t *cscf; |
1227 | |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1228 if (r->headers_in.server.len) { |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1229 v->len = r->headers_in.server.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1230 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
|
1231 |
a6fe6bedb9e3
fix segfault when $host is used and
Igor Sysoev <igor@sysoev.ru>
parents:
864
diff
changeset
|
1232 } else { |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1233 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
|
1234 |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1235 v->len = cscf->server_name.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
1236 v->data = cscf->server_name.data; |
509 | 1237 } |
1238 | |
573 | 1239 v->valid = 1; |
1565 | 1240 v->no_cacheable = 0; |
573 | 1241 v->not_found = 0; |
509 | 1242 |
573 | 1243 return NGX_OK; |
499 | 1244 } |
1245 | |
1246 | |
573 | 1247 static ngx_int_t |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1248 ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, |
573 | 1249 ngx_http_variable_value_t *v, uintptr_t data) |
499 | 1250 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1251 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1252 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1253 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1254 #endif |
982 | 1255 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1256 switch (r->connection->sockaddr->sa_family) { |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1257 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1258 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1259 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1260 sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; |
982 | 1261 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1262 v->len = sizeof(struct in6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1263 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1264 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1265 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
|
1266 v->data = sin6->sin6_addr.s6_addr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1267 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1268 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1269 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1270 |
7121
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1271 #if (NGX_HAVE_UNIX_DOMAIN) |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1272 case AF_UNIX: |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1273 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1274 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
|
1275 v->valid = 1; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1276 v->no_cacheable = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1277 v->not_found = 0; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1278 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
|
1279 |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1280 break; |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1281 #endif |
924b6ef942bf
Fixed handling of unix sockets in $binary_remote_addr.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7077
diff
changeset
|
1282 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1283 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1284 sin = (struct sockaddr_in *) r->connection->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1285 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1286 v->len = sizeof(in_addr_t); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1287 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1288 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1289 v->not_found = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1290 v->data = (u_char *) &sin->sin_addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1291 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1292 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1293 } |
982 | 1294 |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1295 return NGX_OK; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1296 } |
982 | 1297 |
1298 | |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1299 static ngx_int_t |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1300 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
|
1301 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
|
1302 { |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1303 v->len = r->connection->addr_text.len; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1304 v->valid = 1; |
1565 | 1305 v->no_cacheable = 0; |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1306 v->not_found = 0; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1307 v->data = r->connection->addr_text.data; |
499 | 1308 |
573 | 1309 return NGX_OK; |
499 | 1310 } |
1311 | |
1312 | |
573 | 1313 static ngx_int_t |
1314 ngx_http_variable_remote_port(ngx_http_request_t *r, | |
1315 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1316 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1317 ngx_uint_t port; |
509 | 1318 |
573 | 1319 v->len = 0; |
1320 v->valid = 1; | |
1565 | 1321 v->no_cacheable = 0; |
573 | 1322 v->not_found = 0; |
509 | 1323 |
2049 | 1324 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); |
573 | 1325 if (v->data == NULL) { |
1326 return NGX_ERROR; | |
509 | 1327 } |
1328 | |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1329 port = ngx_inet_get_port(r->connection->sockaddr); |
577 | 1330 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1331 if (port > 0 && port < 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1332 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
509 | 1333 } |
1334 | |
573 | 1335 return NGX_OK; |
509 | 1336 } |
1337 | |
1338 | |
573 | 1339 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
|
1340 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
|
1341 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
|
1342 { |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1343 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
|
1344 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
|
1345 |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1346 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
|
1347 if (pp == NULL) { |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1348 v->not_found = 1; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1349 return NGX_OK; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1350 } |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1351 |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1352 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
|
1353 |
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1354 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
|
1355 v->valid = 1; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1356 v->no_cacheable = 0; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1357 v->not_found = 0; |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1358 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
|
1359 |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1360 return NGX_OK; |
3a72b1805c52
Added server-side support for PROXY protocol v1 (ticket #355).
Roman Arutyunyan <arut@nginx.com>
parents:
5464
diff
changeset
|
1361 } |
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 static ngx_int_t |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1365 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
|
1366 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
|
1367 { |
7590
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1368 ngx_uint_t port; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1369 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
|
1370 |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1371 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
|
1372 if (pp == NULL) { |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1373 v->not_found = 1; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1374 return NGX_OK; |
06b01840bd42
Core: moved PROXY protocol fields out of ngx_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
7504
diff
changeset
|
1375 } |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1376 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1377 v->len = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1378 v->valid = 1; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1379 v->no_cacheable = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1380 v->not_found = 0; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1381 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1382 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
|
1383 if (v->data == NULL) { |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1384 return NGX_ERROR; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1385 } |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1386 |
7591
89adf49fe76a
Parsing server PROXY protocol address and port (ticket #1206).
Roman Arutyunyan <arut@nginx.com>
parents:
7590
diff
changeset
|
1387 port = *(in_port_t *) ((char *) pp + data); |
6561
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1388 |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1389 if (port > 0 && port < 65536) { |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1390 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
|
1391 } |
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 return NGX_OK; |
28c76d9d75b7
Added the $proxy_protocol_port variable.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6531
diff
changeset
|
1394 } |
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 static ngx_int_t |
8072
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1398 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
|
1399 ngx_http_variable_value_t *v, uintptr_t data) |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1400 { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1401 ngx_str_t *name = (ngx_str_t *) data; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1402 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1403 ngx_int_t rc; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1404 ngx_str_t tlv, value; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1405 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1406 tlv.len = name->len - (sizeof("proxy_protocol_tlv_") - 1); |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1407 tlv.data = name->data + sizeof("proxy_protocol_tlv_") - 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1408 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1409 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
|
1410 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1411 if (rc == NGX_ERROR) { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1412 return NGX_ERROR; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1413 } |
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 if (rc == NGX_DECLINED) { |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1416 v->not_found = 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1417 return NGX_OK; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1418 } |
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 v->len = value.len; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1421 v->valid = 1; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1422 v->no_cacheable = 0; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1423 v->not_found = 0; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1424 v->data = value.data; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1425 |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1426 return NGX_OK; |
cca4c8a715de
PROXY protocol v2 TLV variables.
Roman Arutyunyan <arut@nginx.com>
parents:
8025
diff
changeset
|
1427 } |
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 static ngx_int_t |
573 | 1431 ngx_http_variable_server_addr(ngx_http_request_t *r, |
1432 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1433 { |
1805 | 1434 ngx_str_t s; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1435 u_char addr[NGX_SOCKADDR_STRLEN]; |
499 | 1436 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1437 s.len = NGX_SOCKADDR_STRLEN; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1438 s.data = addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1439 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1440 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
|
1441 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1442 } |
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 s.data = ngx_pnalloc(r->pool, s.len); |
1805 | 1445 if (s.data == NULL) { |
573 | 1446 return NGX_ERROR; |
509 | 1447 } |
1448 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1449 ngx_memcpy(s.data, addr, s.len); |
509 | 1450 |
1805 | 1451 v->len = s.len; |
573 | 1452 v->valid = 1; |
1565 | 1453 v->no_cacheable = 0; |
573 | 1454 v->not_found = 0; |
1805 | 1455 v->data = s.data; |
499 | 1456 |
573 | 1457 return NGX_OK; |
499 | 1458 } |
1459 | |
1460 | |
573 | 1461 static ngx_int_t |
1462 ngx_http_variable_server_port(ngx_http_request_t *r, | |
1463 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1464 { |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1465 ngx_uint_t port; |
2533 | 1466 |
1467 v->len = 0; | |
573 | 1468 v->valid = 1; |
1565 | 1469 v->no_cacheable = 0; |
573 | 1470 v->not_found = 0; |
2533 | 1471 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1472 if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) { |
2533 | 1473 return NGX_ERROR; |
1474 } | |
1475 | |
1476 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); | |
1477 if (v->data == NULL) { | |
1478 return NGX_ERROR; | |
1479 } | |
1480 | |
6593
b3b7e33083ac
Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
6561
diff
changeset
|
1481 port = ngx_inet_get_port(r->connection->local_sockaddr); |
2533 | 1482 |
1483 if (port > 0 && port < 65536) { | |
1484 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; | |
1485 } | |
509 | 1486 |
573 | 1487 return NGX_OK; |
509 | 1488 } |
1489 | |
1490 | |
573 | 1491 static ngx_int_t |
731 | 1492 ngx_http_variable_scheme(ngx_http_request_t *r, |
1493 ngx_http_variable_value_t *v, uintptr_t data) | |
1494 { | |
1495 #if (NGX_HTTP_SSL) | |
1496 | |
1497 if (r->connection->ssl) { | |
1498 v->len = sizeof("https") - 1; | |
1499 v->valid = 1; | |
1565 | 1500 v->no_cacheable = 0; |
731 | 1501 v->not_found = 0; |
732 | 1502 v->data = (u_char *) "https"; |
731 | 1503 |
1504 return NGX_OK; | |
1505 } | |
1506 | |
1507 #endif | |
1508 | |
1509 v->len = sizeof("http") - 1; | |
1510 v->valid = 1; | |
1565 | 1511 v->no_cacheable = 0; |
731 | 1512 v->not_found = 0; |
732 | 1513 v->data = (u_char *) "http"; |
731 | 1514 |
1515 return NGX_OK; | |
1516 } | |
1517 | |
1518 | |
1519 static ngx_int_t | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1520 ngx_http_variable_https(ngx_http_request_t *r, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1521 ngx_http_variable_value_t *v, uintptr_t data) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1522 { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1523 #if (NGX_HTTP_SSL) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1524 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1525 if (r->connection->ssl) { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1526 v->len = sizeof("on") - 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1527 v->valid = 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1528 v->no_cacheable = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1529 v->not_found = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1530 v->data = (u_char *) "on"; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1531 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1532 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1533 } |
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 #endif |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1536 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1537 *v = ngx_http_variable_null_value; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1538 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1539 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1540 } |
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 |
5699
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1543 static void |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1544 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
|
1545 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
|
1546 { |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1547 r->args.len = v->len; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1548 r->args.data = v->data; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1549 r->valid_unparsed_uri = 0; |
e9dbffc18a77
Setting $args now invalidates unparsed uri.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5677
diff
changeset
|
1550 } |
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 |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1553 static ngx_int_t |
1351 | 1554 ngx_http_variable_is_args(ngx_http_request_t *r, |
1555 ngx_http_variable_value_t *v, uintptr_t data) | |
1556 { | |
1557 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
|
1558 *v = ngx_http_variable_null_value; |
1351 | 1559 return NGX_OK; |
1560 } | |
1561 | |
1562 v->len = 1; | |
7053
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1563 v->valid = 1; |
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1564 v->no_cacheable = 0; |
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
1565 v->not_found = 0; |
1351 | 1566 v->data = (u_char *) "?"; |
1567 | |
1568 return NGX_OK; | |
1569 } | |
1570 | |
1571 | |
1572 static ngx_int_t | |
573 | 1573 ngx_http_variable_document_root(ngx_http_request_t *r, |
1574 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1575 { |
671 | 1576 ngx_str_t path; |
573 | 1577 ngx_http_core_loc_conf_t *clcf; |
509 | 1578 |
1579 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1580 | |
671 | 1581 if (clcf->root_lengths == NULL) { |
1582 v->len = clcf->root.len; | |
1583 v->valid = 1; | |
1565 | 1584 v->no_cacheable = 0; |
671 | 1585 v->not_found = 0; |
1586 v->data = clcf->root.data; | |
1587 | |
1588 } else { | |
1589 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0, | |
1590 clcf->root_values->elts) | |
1591 == NULL) | |
1592 { | |
1593 return NGX_ERROR; | |
1594 } | |
1595 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1596 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
|
1597 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1598 { |
671 | 1599 return NGX_ERROR; |
1600 } | |
1601 | |
1602 v->len = path.len; | |
1603 v->valid = 1; | |
1565 | 1604 v->no_cacheable = 0; |
671 | 1605 v->not_found = 0; |
1606 v->data = path.data; | |
1607 } | |
509 | 1608 |
573 | 1609 return NGX_OK; |
509 | 1610 } |
1611 | |
1612 | |
573 | 1613 static ngx_int_t |
2259 | 1614 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1615 ngx_http_variable_value_t *v, uintptr_t data) | |
1616 { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1617 u_char *real; |
2259 | 1618 size_t len; |
1619 ngx_str_t path; | |
1620 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
|
1621 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1622 u_char buffer[NGX_MAX_PATH]; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1623 #endif |
2259 | 1624 |
1625 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1626 | |
1627 if (clcf->root_lengths == NULL) { | |
1628 path = clcf->root; | |
1629 | |
1630 } else { | |
1631 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1, | |
1632 clcf->root_values->elts) | |
1633 == NULL) | |
1634 { | |
1635 return NGX_ERROR; | |
1636 } | |
1637 | |
1638 path.data[path.len - 1] = '\0'; | |
1639 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1640 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
|
1641 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1642 { |
2259 | 1643 return NGX_ERROR; |
1644 } | |
1645 } | |
1646 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1647 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1648 real = buffer; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1649 #else |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1650 real = NULL; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1651 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1652 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1653 real = ngx_realpath(path.data, real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1654 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1655 if (real == NULL) { |
2259 | 1656 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1657 ngx_realpath_n " \"%s\" failed", path.data); | |
1658 return NGX_ERROR; | |
1659 } | |
1660 | |
1661 len = ngx_strlen(real); | |
1662 | |
1663 v->data = ngx_pnalloc(r->pool, len); | |
1664 if (v->data == NULL) { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1665 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1666 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1667 #endif |
2259 | 1668 return NGX_ERROR; |
1669 } | |
1670 | |
1671 v->len = len; | |
1672 v->valid = 1; | |
1673 v->no_cacheable = 0; | |
1674 v->not_found = 0; | |
1675 | |
1676 ngx_memcpy(v->data, real, len); | |
1677 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1678 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1679 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1680 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1681 |
2259 | 1682 return NGX_OK; |
1683 } | |
1684 | |
1685 | |
1686 static ngx_int_t | |
573 | 1687 ngx_http_variable_request_filename(ngx_http_request_t *r, |
1688 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1689 { |
773 | 1690 size_t root; |
573 | 1691 ngx_str_t path; |
499 | 1692 |
773 | 1693 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
573 | 1694 return NGX_ERROR; |
557 | 1695 } |
509 | 1696 |
557 | 1697 /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */ |
509 | 1698 |
573 | 1699 v->len = path.len - 1; |
1700 v->valid = 1; | |
1565 | 1701 v->no_cacheable = 0; |
573 | 1702 v->not_found = 0; |
1703 v->data = path.data; | |
499 | 1704 |
573 | 1705 return NGX_OK; |
499 | 1706 } |
1707 | |
1708 | |
573 | 1709 static ngx_int_t |
1811 | 1710 ngx_http_variable_server_name(ngx_http_request_t *r, |
1711 ngx_http_variable_value_t *v, uintptr_t data) | |
1712 { | |
1713 ngx_http_core_srv_conf_t *cscf; | |
1714 | |
1715 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1716 | |
1717 v->len = cscf->server_name.len; | |
1718 v->valid = 1; | |
1719 v->no_cacheable = 0; | |
1720 v->not_found = 0; | |
1721 v->data = cscf->server_name.data; | |
1722 | |
1723 return NGX_OK; | |
1724 } | |
1725 | |
1726 | |
1727 static ngx_int_t | |
573 | 1728 ngx_http_variable_request_method(ngx_http_request_t *r, |
1729 ngx_http_variable_value_t *v, uintptr_t data) | |
561 | 1730 { |
647 | 1731 if (r->main->method_name.data) { |
1732 v->len = r->main->method_name.len; | |
573 | 1733 v->valid = 1; |
1565 | 1734 v->no_cacheable = 0; |
573 | 1735 v->not_found = 0; |
647 | 1736 v->data = r->main->method_name.data; |
573 | 1737 |
1738 } else { | |
1739 v->not_found = 1; | |
561 | 1740 } |
1741 | |
573 | 1742 return NGX_OK; |
561 | 1743 } |
1744 | |
1745 | |
573 | 1746 static ngx_int_t |
1747 ngx_http_variable_remote_user(ngx_http_request_t *r, | |
1748 ngx_http_variable_value_t *v, uintptr_t data) | |
539 | 1749 { |
573 | 1750 ngx_int_t rc; |
539 | 1751 |
1752 rc = ngx_http_auth_basic_user(r); | |
1753 | |
1754 if (rc == NGX_DECLINED) { | |
573 | 1755 v->not_found = 1; |
1756 return NGX_OK; | |
539 | 1757 } |
1758 | |
1759 if (rc == NGX_ERROR) { | |
573 | 1760 return NGX_ERROR; |
539 | 1761 } |
1762 | |
573 | 1763 v->len = r->headers_in.user.len; |
1764 v->valid = 1; | |
1565 | 1765 v->no_cacheable = 0; |
573 | 1766 v->not_found = 0; |
1767 v->data = r->headers_in.user.data; | |
571 | 1768 |
573 | 1769 return NGX_OK; |
571 | 1770 } |
1771 | |
1772 | |
611 | 1773 static ngx_int_t |
4886 | 1774 ngx_http_variable_bytes_sent(ngx_http_request_t *r, |
1775 ngx_http_variable_value_t *v, uintptr_t data) | |
1776 { | |
1777 u_char *p; | |
1778 | |
1779 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); | |
1780 if (p == NULL) { | |
1781 return NGX_ERROR; | |
1782 } | |
1783 | |
1784 v->len = ngx_sprintf(p, "%O", r->connection->sent) - p; | |
1785 v->valid = 1; | |
1786 v->no_cacheable = 0; | |
1787 v->not_found = 0; | |
1788 v->data = p; | |
1789 | |
1790 return NGX_OK; | |
1791 } | |
1792 | |
1793 | |
1794 static ngx_int_t | |
611 | 1795 ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
1796 ngx_http_variable_value_t *v, uintptr_t data) | |
1797 { | |
1798 off_t sent; | |
1799 u_char *p; | |
1800 | |
1801 sent = r->connection->sent - r->header_size; | |
1802 | |
1803 if (sent < 0) { | |
1804 sent = 0; | |
1805 } | |
1806 | |
2049 | 1807 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
611 | 1808 if (p == NULL) { |
1809 return NGX_ERROR; | |
1810 } | |
1811 | |
1812 v->len = ngx_sprintf(p, "%O", sent) - p; | |
1813 v->valid = 1; | |
1565 | 1814 v->no_cacheable = 0; |
611 | 1815 v->not_found = 0; |
1816 v->data = p; | |
1817 | |
1818 return NGX_OK; | |
1819 } | |
1820 | |
1821 | |
629 | 1822 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1823 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
|
1824 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
|
1825 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1826 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
|
1827 v->len = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1828 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1829 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1830 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1831 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1832 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1833 } |
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 static ngx_int_t |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1837 ngx_http_variable_status(ngx_http_request_t *r, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1838 ngx_http_variable_value_t *v, uintptr_t data) |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1839 { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1840 ngx_uint_t status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1841 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1842 v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1843 if (v->data == NULL) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1844 return NGX_ERROR; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1845 } |
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 if (r->err_status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1848 status = r->err_status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1849 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1850 } else if (r->headers_out.status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1851 status = r->headers_out.status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1852 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1853 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1854 status = 9; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1855 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1856 } else { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1857 status = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1858 } |
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 v->len = ngx_sprintf(v->data, "%03ui", status) - v->data; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1861 v->valid = 1; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1862 v->no_cacheable = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1863 v->not_found = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1864 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1865 return NGX_OK; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1866 } |
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 static ngx_int_t |
641 | 1870 ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
1871 ngx_http_variable_value_t *v, uintptr_t data) | |
1872 { | |
1873 if (r->headers_out.content_type.len) { | |
1874 v->len = r->headers_out.content_type.len; | |
1875 v->valid = 1; | |
1565 | 1876 v->no_cacheable = 0; |
641 | 1877 v->not_found = 0; |
1878 v->data = r->headers_out.content_type.data; | |
1879 | |
1880 } else { | |
1881 v->not_found = 1; | |
1882 } | |
1883 | |
1884 return NGX_OK; | |
1885 } | |
1886 | |
1887 | |
1888 static ngx_int_t | |
1889 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
1890 ngx_http_variable_value_t *v, uintptr_t data) | |
1891 { | |
1892 u_char *p; | |
1893 | |
1894 if (r->headers_out.content_length) { | |
1895 v->len = r->headers_out.content_length->value.len; | |
1896 v->valid = 1; | |
1565 | 1897 v->no_cacheable = 0; |
641 | 1898 v->not_found = 0; |
1899 v->data = r->headers_out.content_length->value.data; | |
1900 | |
1901 return NGX_OK; | |
1902 } | |
1903 | |
1904 if (r->headers_out.content_length_n >= 0) { | |
2049 | 1905 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
641 | 1906 if (p == NULL) { |
1907 return NGX_ERROR; | |
1908 } | |
1909 | |
1910 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
1911 v->valid = 1; | |
1565 | 1912 v->no_cacheable = 0; |
641 | 1913 v->not_found = 0; |
1914 v->data = p; | |
1915 | |
1916 return NGX_OK; | |
1917 } | |
1918 | |
1919 v->not_found = 1; | |
1920 | |
1921 return NGX_OK; | |
1922 } | |
1923 | |
1924 | |
1925 static ngx_int_t | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1926 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
|
1927 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
|
1928 { |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1929 ngx_str_t name; |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1930 |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1931 if (r->headers_out.location) { |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1932 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
|
1933 v->valid = 1; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1934 v->no_cacheable = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1935 v->not_found = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1936 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
|
1937 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1938 return NGX_OK; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1939 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1940 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
1941 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
|
1942 |
8023
08b3ea81ff5f
Combining unknown headers during variables lookup (ticket #1316).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7930
diff
changeset
|
1943 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
|
1944 &r->headers_out.headers.part, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1945 sizeof("sent_http_") - 1); |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1946 } |
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 static ngx_int_t |
641 | 1950 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
1951 ngx_http_variable_value_t *v, uintptr_t data) | |
1952 { | |
1953 u_char *p; | |
1954 | |
1955 if (r->headers_out.last_modified) { | |
1956 v->len = r->headers_out.last_modified->value.len; | |
1957 v->valid = 1; | |
1565 | 1958 v->no_cacheable = 0; |
641 | 1959 v->not_found = 0; |
1960 v->data = r->headers_out.last_modified->value.data; | |
1961 | |
1962 return NGX_OK; | |
1963 } | |
1964 | |
1965 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
|
1966 p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
641 | 1967 if (p == NULL) { |
1968 return NGX_ERROR; | |
1969 } | |
1970 | |
1971 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
1972 v->valid = 1; | |
1565 | 1973 v->no_cacheable = 0; |
641 | 1974 v->not_found = 0; |
1975 v->data = p; | |
1976 | |
1977 return NGX_OK; | |
1978 } | |
1979 | |
1980 v->not_found = 1; | |
1981 | |
1982 return NGX_OK; | |
1983 } | |
1984 | |
1985 | |
1986 static ngx_int_t | |
1987 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
1988 ngx_http_variable_value_t *v, uintptr_t data) | |
1989 { | |
1990 size_t len; | |
1991 char *p; | |
1992 | |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1993 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
|
1994 len = sizeof("upgrade") - 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1995 p = "upgrade"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1996 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1997 } else if (r->keepalive) { |
641 | 1998 len = sizeof("keep-alive") - 1; |
1999 p = "keep-alive"; | |
2000 | |
2001 } else { | |
2002 len = sizeof("close") - 1; | |
2003 p = "close"; | |
2004 } | |
2005 | |
2006 v->len = len; | |
2007 v->valid = 1; | |
1565 | 2008 v->no_cacheable = 0; |
641 | 2009 v->not_found = 0; |
2010 v->data = (u_char *) p; | |
2011 | |
2012 return NGX_OK; | |
2013 } | |
2014 | |
2015 | |
2016 static ngx_int_t | |
2017 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
2018 ngx_http_variable_value_t *v, uintptr_t data) | |
2019 { | |
2020 u_char *p; | |
2021 ngx_http_core_loc_conf_t *clcf; | |
2022 | |
2023 if (r->keepalive) { | |
2024 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
2025 | |
2026 if (clcf->keepalive_header) { | |
2027 | |
2049 | 2028 p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); |
641 | 2029 if (p == NULL) { |
2030 return NGX_ERROR; | |
2031 } | |
2032 | |
2033 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
2034 v->valid = 1; | |
1565 | 2035 v->no_cacheable = 0; |
641 | 2036 v->not_found = 0; |
2037 v->data = p; | |
2038 | |
2039 return NGX_OK; | |
2040 } | |
2041 } | |
2042 | |
2043 v->not_found = 1; | |
2044 | |
2045 return NGX_OK; | |
2046 } | |
2047 | |
2048 | |
2049 static ngx_int_t | |
2050 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
2051 ngx_http_variable_value_t *v, uintptr_t data) | |
2052 { | |
2053 if (r->chunked) { | |
2054 v->len = sizeof("chunked") - 1; | |
2055 v->valid = 1; | |
1565 | 2056 v->no_cacheable = 0; |
641 | 2057 v->not_found = 0; |
2058 v->data = (u_char *) "chunked"; | |
2059 | |
2060 } else { | |
2061 v->not_found = 1; | |
2062 } | |
2063 | |
2064 return NGX_OK; | |
2065 } | |
2066 | |
2067 | |
7504
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2068 static void |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2069 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
|
2070 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
|
2071 { |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2072 ssize_t s; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2073 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
|
2074 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2075 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
|
2076 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
|
2077 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2078 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
|
2079 |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2080 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
|
2081 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
|
2082 "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
|
2083 return; |
c19ca381b2e6
Variables support in limit_rate and limit_rate_after (ticket #293).
Ruslan Ermilov <ru@nginx.com>
parents:
7427
diff
changeset
|
2084 } |
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 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
|
2087 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
|
2088 } |
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 |
641 | 2091 static ngx_int_t |
629 | 2092 ngx_http_variable_request_completion(ngx_http_request_t *r, |
2093 ngx_http_variable_value_t *v, uintptr_t data) | |
2094 { | |
2095 if (r->request_complete) { | |
2096 v->len = 2; | |
2097 v->valid = 1; | |
1565 | 2098 v->no_cacheable = 0; |
629 | 2099 v->not_found = 0; |
2100 v->data = (u_char *) "OK"; | |
2101 | |
2102 return NGX_OK; | |
2103 } | |
2104 | |
7053
7f480434c7f2
Variables: use ngx_http_variable_null_value where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
7034
diff
changeset
|
2105 *v = ngx_http_variable_null_value; |
629 | 2106 |
2107 return NGX_OK; | |
2108 } | |
2109 | |
2110 | |
759 | 2111 static ngx_int_t |
2844 | 2112 ngx_http_variable_request_body(ngx_http_request_t *r, |
2113 ngx_http_variable_value_t *v, uintptr_t data) | |
2114 { | |
2115 u_char *p; | |
2116 size_t len; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2117 ngx_buf_t *buf; |
2844 | 2118 ngx_chain_t *cl; |
2119 | |
2878
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2120 if (r->request_body == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2121 || r->request_body->bufs == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2122 || r->request_body->temp_file) |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
2123 { |
2844 | 2124 v->not_found = 1; |
2125 | |
2126 return NGX_OK; | |
2127 } | |
2128 | |
2129 cl = r->request_body->bufs; | |
2130 buf = cl->buf; | |
2131 | |
2132 if (cl->next == NULL) { | |
2133 v->len = buf->last - buf->pos; | |
2134 v->valid = 1; | |
2135 v->no_cacheable = 0; | |
2136 v->not_found = 0; | |
2137 v->data = buf->pos; | |
2138 | |
2139 return NGX_OK; | |
2140 } | |
2141 | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2142 len = buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2143 cl = cl->next; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2144 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2145 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2146 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2147 len += buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2148 } |
2844 | 2149 |
2150 p = ngx_pnalloc(r->pool, len); | |
2151 if (p == NULL) { | |
2152 return NGX_ERROR; | |
2153 } | |
2154 | |
2155 v->data = p; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2156 cl = r->request_body->bufs; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2157 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2158 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2159 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
2160 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
|
2161 } |
2844 | 2162 |
2163 v->len = len; | |
2164 v->valid = 1; | |
2165 v->no_cacheable = 0; | |
2166 v->not_found = 0; | |
2167 | |
2168 return NGX_OK; | |
2169 } | |
2170 | |
2171 | |
2172 static ngx_int_t | |
759 | 2173 ngx_http_variable_request_body_file(ngx_http_request_t *r, |
2174 ngx_http_variable_value_t *v, uintptr_t data) | |
2175 { | |
2176 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
|
2177 v->not_found = 1; |
759 | 2178 |
2179 return NGX_OK; | |
2180 } | |
2181 | |
2182 v->len = r->request_body->temp_file->file.name.len; | |
2183 v->valid = 1; | |
1565 | 2184 v->no_cacheable = 0; |
759 | 2185 v->not_found = 0; |
2186 v->data = r->request_body->temp_file->file.name.data; | |
2187 | |
2188 return NGX_OK; | |
2189 } | |
2190 | |
2191 | |
1329 | 2192 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2193 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
|
2194 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
|
2195 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2196 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2197 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2198 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
|
2199 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2200 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2201 } |
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 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
|
2204 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2205 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2206 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2207 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2208 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2209 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2210 } |
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 static ngx_int_t |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2214 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
|
2215 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2216 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2217 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2218 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2219 ngx_msec_int_t ms; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2220 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2221 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
|
2222 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2223 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2224 } |
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 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2227 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2228 ms = (ngx_msec_int_t) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2229 ((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
|
2230 ms = ngx_max(ms, 0); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2231 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5327
diff
changeset
|
2232 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
|
2233 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2234 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2235 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2236 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2237 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2238 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2239 } |
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 static ngx_int_t |
6531 | 2243 ngx_http_variable_request_id(ngx_http_request_t *r, |
2244 ngx_http_variable_value_t *v, uintptr_t data) | |
2245 { | |
2246 u_char *id; | |
2247 | |
2248 #if (NGX_OPENSSL) | |
2249 u_char random_bytes[16]; | |
2250 #endif | |
2251 | |
2252 id = ngx_pnalloc(r->pool, 32); | |
2253 if (id == NULL) { | |
2254 return NGX_ERROR; | |
2255 } | |
2256 | |
2257 v->valid = 1; | |
2258 v->no_cacheable = 0; | |
2259 v->not_found = 0; | |
2260 | |
2261 v->len = 32; | |
2262 v->data = id; | |
2263 | |
2264 #if (NGX_OPENSSL) | |
2265 | |
2266 if (RAND_bytes(random_bytes, 16) == 1) { | |
2267 ngx_hex_dump(id, random_bytes, 16); | |
2268 return NGX_OK; | |
2269 } | |
2270 | |
2271 ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0, "RAND_bytes() failed"); | |
2272 | |
2273 #endif | |
2274 | |
2275 ngx_sprintf(id, "%08xD%08xD%08xD%08xD", | |
2276 (uint32_t) ngx_random(), (uint32_t) ngx_random(), | |
2277 (uint32_t) ngx_random(), (uint32_t) ngx_random()); | |
2278 | |
2279 return NGX_OK; | |
2280 } | |
2281 | |
2282 | |
2283 static ngx_int_t | |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2284 ngx_http_variable_connection(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2285 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2286 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2287 u_char *p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2288 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2289 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2290 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2291 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2292 } |
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 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
|
2295 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2296 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2297 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2298 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2299 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2300 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2301 } |
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 static ngx_int_t |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2305 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
|
2306 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2307 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2308 u_char *p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2309 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2310 p = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2311 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2312 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2313 } |
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 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
|
2316 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2317 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2318 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2319 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2320 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2321 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2322 } |
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 static ngx_int_t |
7821
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2326 ngx_http_variable_connection_time(ngx_http_request_t *r, |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2327 ngx_http_variable_value_t *v, uintptr_t data) |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2328 { |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2329 u_char *p; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2330 ngx_msec_int_t ms; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2331 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2332 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2333 if (p == NULL) { |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2334 return NGX_ERROR; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2335 } |
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 ms = ngx_current_msec - r->connection->start_time; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2338 ms = ngx_max(ms, 0); |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2339 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2340 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
|
2341 v->valid = 1; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2342 v->no_cacheable = 0; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2343 v->not_found = 0; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2344 v->data = p; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2345 |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2346 return NGX_OK; |
6d4f7d5e279f
Added $connection_time variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7648
diff
changeset
|
2347 } |
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 static ngx_int_t |
1329 | 2351 ngx_http_variable_nginx_version(ngx_http_request_t *r, |
2352 ngx_http_variable_value_t *v, uintptr_t data) | |
2353 { | |
2354 v->len = sizeof(NGINX_VERSION) - 1; | |
2355 v->valid = 1; | |
1565 | 2356 v->no_cacheable = 0; |
1329 | 2357 v->not_found = 0; |
2358 v->data = (u_char *) NGINX_VERSION; | |
2359 | |
2360 return NGX_OK; | |
2361 } | |
2362 | |
2363 | |
2011 | 2364 static ngx_int_t |
2365 ngx_http_variable_hostname(ngx_http_request_t *r, | |
2366 ngx_http_variable_value_t *v, uintptr_t data) | |
2367 { | |
2368 v->len = ngx_cycle->hostname.len; | |
2369 v->valid = 1; | |
2370 v->no_cacheable = 0; | |
2371 v->not_found = 0; | |
2372 v->data = ngx_cycle->hostname.data; | |
2373 | |
2374 return NGX_OK; | |
2375 } | |
2376 | |
2377 | |
2249 | 2378 static ngx_int_t |
2379 ngx_http_variable_pid(ngx_http_request_t *r, | |
2380 ngx_http_variable_value_t *v, uintptr_t data) | |
2381 { | |
2382 u_char *p; | |
2383 | |
2384 p = ngx_pnalloc(r->pool, NGX_INT64_LEN); | |
2385 if (p == NULL) { | |
2386 return NGX_ERROR; | |
2387 } | |
2388 | |
2389 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; | |
2390 v->valid = 1; | |
2391 v->no_cacheable = 0; | |
2392 v->not_found = 0; | |
2393 v->data = p; | |
2394 | |
2395 return NGX_OK; | |
2396 } | |
2397 | |
2398 | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2399 static ngx_int_t |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2400 ngx_http_variable_msec(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2401 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2402 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2403 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2404 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2405 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2406 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
|
2407 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2408 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2409 } |
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 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2412 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2413 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
|
2414 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2415 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2416 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2417 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2418 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2419 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2420 } |
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 |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2423 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2424 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
|
2425 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
|
2426 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2427 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2428 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2429 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
|
2430 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2431 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2432 } |
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 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
|
2435 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
|
2436 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2437 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
|
2438 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2439 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2440 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2441 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2442 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2443 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2444 } |
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 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2448 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
|
2449 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
|
2450 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2451 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2452 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2453 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
|
2454 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2455 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2456 } |
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 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
|
2459 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2460 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
|
2461 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2462 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2463 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2464 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2465 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2466 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2467 } |
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 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2470 void * |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2471 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
|
2472 { |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2473 void *value; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2474 u_char *low; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2475 size_t len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2476 ngx_uint_t key; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2477 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2478 len = match->len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2479 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2480 if (len) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2481 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
|
2482 if (low == NULL) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2483 return NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2484 } |
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 } else { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2487 low = NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2488 } |
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 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
|
2491 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2492 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
|
2493 if (value) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2494 return value; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2495 } |
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 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2498 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2499 if (len && map->nregex) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2500 ngx_int_t n; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2501 ngx_uint_t i; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2502 ngx_http_map_regex_t *reg; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2503 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2504 reg = map->regex; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2505 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2506 for (i = 0; i < map->nregex; i++) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2507 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2508 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
|
2509 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2510 if (n == NGX_OK) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2511 return reg[i].value; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2512 } |
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 if (n == NGX_DECLINED) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2515 continue; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2516 } |
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 /* NGX_ERROR */ |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2519 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2520 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2521 } |
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 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2525 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2526 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2527 } |
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 |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2530 #if (NGX_PCRE) |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2531 |
3325 | 2532 static ngx_int_t |
2533 ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
2534 uintptr_t data) | |
2535 { | |
2536 v->not_found = 1; | |
2537 return NGX_OK; | |
2538 } | |
2539 | |
2540 | |
2541 ngx_http_regex_t * | |
2542 ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
2543 { | |
2544 u_char *p; | |
2545 size_t size; | |
2546 ngx_str_t name; | |
2547 ngx_uint_t i, n; | |
2548 ngx_http_variable_t *v; | |
2549 ngx_http_regex_t *re; | |
2550 ngx_http_regex_variable_t *rv; | |
2551 ngx_http_core_main_conf_t *cmcf; | |
2552 | |
2553 rc->pool = cf->pool; | |
2554 | |
2555 if (ngx_regex_compile(rc) != NGX_OK) { | |
2556 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
2557 return NULL; | |
2558 } | |
2559 | |
2560 re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t)); | |
2561 if (re == NULL) { | |
2562 return NULL; | |
2563 } | |
2564 | |
2565 re->regex = rc->regex; | |
2566 re->ncaptures = rc->captures; | |
5204
a64c8a5da336
PCRE: retain input pattern for all regular expressions.
Piotr Sikora <piotr@cloudflare.com>
parents:
5084
diff
changeset
|
2567 re->name = rc->pattern; |
3325 | 2568 |
2569 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2570 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
2571 | |
2572 n = (ngx_uint_t) rc->named_captures; | |
2573 | |
2574 if (n == 0) { | |
2575 return re; | |
2576 } | |
2577 | |
2578 rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t)); | |
2579 if (rv == NULL) { | |
2580 return NULL; | |
2581 } | |
2582 | |
2583 re->variables = rv; | |
2584 re->nvariables = n; | |
2585 | |
2586 size = rc->name_size; | |
2587 p = rc->names; | |
2588 | |
2589 for (i = 0; i < n; i++) { | |
2590 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
2591 | |
2592 name.data = &p[2]; | |
2593 name.len = ngx_strlen(name.data); | |
2594 | |
2595 v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); | |
2596 if (v == NULL) { | |
2597 return NULL; | |
2598 } | |
2599 | |
2600 rv[i].index = ngx_http_get_variable_index(cf, &name); | |
2601 if (rv[i].index == NGX_ERROR) { | |
2602 return NULL; | |
2603 } | |
2604 | |
2605 v->get_handler = ngx_http_variable_not_found; | |
2606 | |
3409
bb79608169eb
named captures worked for two names only
Igor Sysoev <igor@sysoev.ru>
parents:
3356
diff
changeset
|
2607 p += size; |
3325 | 2608 } |
2609 | |
2610 return re; | |
2611 } | |
2612 | |
2613 | |
2614 ngx_int_t | |
2615 ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s) | |
2616 { | |
2617 ngx_int_t rc, index; | |
2618 ngx_uint_t i, n, len; | |
2619 ngx_http_variable_value_t *vv; | |
2620 ngx_http_core_main_conf_t *cmcf; | |
2621 | |
2622 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
2623 | |
2624 if (re->ncaptures) { | |
3345
d8228f0b5113
evaluate maximum captures size on configuration phase
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
2625 len = cmcf->ncaptures; |
3325 | 2626 |
7427
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2627 if (r->captures == NULL || r->realloc_captures) { |
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2628 r->realloc_captures = 0; |
81d49f85afed
Copy regex unnamed captures to cloned subrequests.
Roman Arutyunyan <arut@nginx.com>
parents:
7226
diff
changeset
|
2629 |
3325 | 2630 r->captures = ngx_palloc(r->pool, len * sizeof(int)); |
2631 if (r->captures == NULL) { | |
2632 return NGX_ERROR; | |
2633 } | |
2634 } | |
2635 | |
2636 } else { | |
2637 len = 0; | |
2638 } | |
2639 | |
2640 rc = ngx_regex_exec(re->regex, s, r->captures, len); | |
2641 | |
2642 if (rc == NGX_REGEX_NO_MATCHED) { | |
2643 return NGX_DECLINED; | |
2644 } | |
2645 | |
2646 if (rc < 0) { | |
2647 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
2648 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
2649 rc, s, &re->name); | |
2650 return NGX_ERROR; | |
2651 } | |
2652 | |
2653 for (i = 0; i < re->nvariables; i++) { | |
2654 | |
2655 n = re->variables[i].capture; | |
2656 index = re->variables[i].index; | |
2657 vv = &r->variables[index]; | |
2658 | |
2659 vv->len = r->captures[n + 1] - r->captures[n]; | |
2660 vv->valid = 1; | |
2661 vv->no_cacheable = 0; | |
2662 vv->not_found = 0; | |
2663 vv->data = &s->data[r->captures[n]]; | |
2664 | |
2665 #if (NGX_DEBUG) | |
2666 { | |
2667 ngx_http_variable_t *v; | |
2668 | |
2669 v = cmcf->variables.elts; | |
2670 | |
6478
3ef7bb882ad4
Fixed logging with variable field width.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6263
diff
changeset
|
2671 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
|
2672 "http regex set $%V to \"%v\"", &v[index].name, vv); |
3325 | 2673 } |
2674 #endif | |
2675 } | |
2676 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2677 r->ncaptures = rc * 2; |
3325 | 2678 r->captures_data = s->data; |
2679 | |
2680 return NGX_OK; | |
2681 } | |
2682 | |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2683 #endif |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2684 |
3325 | 2685 |
499 | 2686 ngx_int_t |
509 | 2687 ngx_http_variables_add_core_vars(ngx_conf_t *cf) |
499 | 2688 { |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2689 ngx_http_variable_t *cv, *v; |
501 | 2690 ngx_http_core_main_conf_t *cmcf; |
499 | 2691 |
509 | 2692 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2693 | |
611 | 2694 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, |
2695 sizeof(ngx_hash_keys_arrays_t)); | |
2696 if (cmcf->variables_keys == NULL) { | |
2697 return NGX_ERROR; | |
2698 } | |
2699 | |
2700 cmcf->variables_keys->pool = cf->pool; | |
2701 cmcf->variables_keys->temp_pool = cf->pool; | |
2702 | |
2703 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
2704 != NGX_OK) | |
509 | 2705 { |
499 | 2706 return NGX_ERROR; |
2707 } | |
2708 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2709 if (ngx_array_init(&cmcf->prefix_variables, cf->pool, 8, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2710 sizeof(ngx_http_variable_t)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2711 != NGX_OK) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2712 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2713 return NGX_ERROR; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2714 } |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2715 |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2716 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
|
2717 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
|
2718 if (v == NULL) { |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2719 return NGX_ERROR; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2720 } |
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 *v = *cv; |
499 | 2723 } |
2724 | |
2725 return NGX_OK; | |
2726 } | |
509 | 2727 |
2728 | |
2729 ngx_int_t | |
2730 ngx_http_variables_init_vars(ngx_conf_t *cf) | |
2731 { | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2732 size_t len; |
509 | 2733 ngx_uint_t i, n; |
611 | 2734 ngx_hash_key_t *key; |
2735 ngx_hash_init_t hash; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2736 ngx_http_variable_t *v, *av, *pv; |
509 | 2737 ngx_http_core_main_conf_t *cmcf; |
2738 | |
2739 /* set the handlers for the indexed http variables */ | |
2740 | |
2741 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2742 | |
2743 v = cmcf->variables.elts; | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2744 pv = cmcf->prefix_variables.elts; |
611 | 2745 key = cmcf->variables_keys->keys.elts; |
509 | 2746 |
2747 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2748 | |
611 | 2749 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
509 | 2750 |
1191
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2751 av = key[n].value; |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2752 |
5815
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2753 if (v[i].name.len == key[n].key.len |
611 | 2754 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) |
509 | 2755 == 0) |
2756 { | |
637 | 2757 v[i].get_handler = av->get_handler; |
611 | 2758 v[i].data = av->data; |
527 | 2759 |
611 | 2760 av->flags |= NGX_HTTP_VAR_INDEXED; |
2761 v[i].flags = av->flags; | |
509 | 2762 |
611 | 2763 av->index = i; |
533 | 2764 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2765 if (av->get_handler == NULL |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2766 || (av->flags & NGX_HTTP_VAR_WEAK)) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2767 { |
5815
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2768 break; |
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2769 } |
6c99c5f00fc9
Variables: fixed non-indexed access of prefix vars (ticket #600).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5699
diff
changeset
|
2770 |
509 | 2771 goto next; |
2772 } | |
2773 } | |
2774 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2775 len = 0; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2776 av = NULL; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2777 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2778 for (n = 0; n < cmcf->prefix_variables.nelts; n++) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2779 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
|
2780 && 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
|
2781 == 0) |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2782 { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2783 av = &pv[n]; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2784 len = pv[n].name.len; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2785 } |
1162 | 2786 } |
2787 | |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2788 if (av) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2789 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
|
2790 v[i].data = (uintptr_t) &v[i].name; |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2791 v[i].flags = av->flags; |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2792 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2793 goto next; |
5677
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5605
diff
changeset
|
2794 } |
3a48775f1535
Upstream: added the "$upstream_cookie_<name>" variables.
Vladimir Homutov <vl@nginx.com>
parents:
5605
diff
changeset
|
2795 |
6899
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2796 if (v[i].get_handler == NULL) { |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2797 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2798 "unknown \"%V\" variable", &v[i].name); |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2799 |
d2b2ff157da5
Variables: generic prefix variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6851
diff
changeset
|
2800 return NGX_ERROR; |
2137 | 2801 } |
2802 | |
509 | 2803 next: |
2804 continue; | |
2805 } | |
2806 | |
2807 | |
611 | 2808 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
2809 av = key[n].value; | |
2810 | |
2811 if (av->flags & NGX_HTTP_VAR_NOHASH) { | |
2812 key[n].key.data = NULL; | |
583 | 2813 } |
2814 } | |
2815 | |
2816 | |
611 | 2817 hash.hash = &cmcf->variables_hash; |
2818 hash.key = ngx_hash_key; | |
2819 hash.max_size = cmcf->variables_hash_max_size; | |
2820 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
2821 hash.name = "variables_hash"; | |
2822 hash.pool = cf->pool; | |
2823 hash.temp_pool = NULL; | |
509 | 2824 |
611 | 2825 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, |
2826 cmcf->variables_keys->keys.nelts) | |
581 | 2827 != NGX_OK) |
509 | 2828 { |
2829 return NGX_ERROR; | |
2830 } | |
2831 | |
611 | 2832 cmcf->variables_keys = NULL; |
509 | 2833 |
2834 return NGX_OK; | |
2835 } |