Mercurial > hg > nginx-quic
annotate src/http/ngx_http_variables.c @ 4666:0bb016b1fd2d stable-1.2
Merge of r4621, r4641: filter_finalize fixes.
*) Fixed possible request hang with filter finalization.
With r->filter_finalize set the ngx_http_finalize_connection() wasn't
called from ngx_http_finalize_request() called with NGX_OK, resulting in
r->main->count not being decremented, thus causing request hang in some
rare situations.
Patch by Yichun Zhang (agentzh).
*) Fixed segfault with filter_finalize introduced in r4621 (1.3.0).
See the following thread for more details:
http://mailman.nginx.org/pipermail/nginx-devel/2012-May/002190.html
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 04 Jun 2012 11:15:46 +0000 |
parents | 67653855682e |
children | 045bb3ef3ffc |
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 | |
573 | 14 static ngx_int_t ngx_http_variable_request(ngx_http_request_t *r, |
15 ngx_http_variable_value_t *v, uintptr_t data); | |
1350 | 16 static void ngx_http_variable_request_set(ngx_http_request_t *r, |
17 ngx_http_variable_value_t *v, uintptr_t data); | |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
18 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
|
19 ngx_http_variable_value_t *v, uintptr_t data); |
637 | 20 static void ngx_http_variable_request_set_size(ngx_http_request_t *r, |
21 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 22 static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r, |
23 ngx_http_variable_value_t *v, uintptr_t data); | |
24 static ngx_int_t ngx_http_variable_headers(ngx_http_request_t *r, | |
25 ngx_http_variable_value_t *v, uintptr_t data); | |
577 | 26 |
27 static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r, | |
573 | 28 ngx_http_variable_value_t *v, uintptr_t data); |
577 | 29 static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r, |
30 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
|
31 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
|
32 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
|
33 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
|
34 ngx_http_variable_value_t *v, uintptr_t data); |
2137 | 35 static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r, |
36 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
|
37 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
38 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
|
39 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
|
40 #endif |
577 | 41 |
573 | 42 static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, |
43 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
|
44 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
|
45 ngx_http_variable_value_t *v, uintptr_t data); |
573 | 46 static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r, |
47 ngx_http_variable_value_t *v, uintptr_t data); | |
48 static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r, | |
49 ngx_http_variable_value_t *v, uintptr_t data); | |
50 static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r, | |
51 ngx_http_variable_value_t *v, uintptr_t data); | |
52 static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r, | |
53 ngx_http_variable_value_t *v, uintptr_t data); | |
731 | 54 static ngx_int_t ngx_http_variable_scheme(ngx_http_request_t *r, |
55 ngx_http_variable_value_t *v, uintptr_t data); | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
56 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
|
57 ngx_http_variable_value_t *v, uintptr_t data); |
1351 | 58 static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r, |
59 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 60 static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r, |
61 ngx_http_variable_value_t *v, uintptr_t data); | |
2259 | 62 static ngx_int_t ngx_http_variable_realpath_root(ngx_http_request_t *r, |
63 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 64 static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r, |
65 ngx_http_variable_value_t *v, uintptr_t data); | |
1811 | 66 static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r, |
67 ngx_http_variable_value_t *v, uintptr_t data); | |
573 | 68 static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r, |
69 ngx_http_variable_value_t *v, uintptr_t data); | |
70 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, | |
71 ngx_http_variable_value_t *v, uintptr_t data); | |
611 | 72 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
73 ngx_http_variable_value_t *v, uintptr_t data); | |
629 | 74 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, |
75 ngx_http_variable_value_t *v, uintptr_t data); | |
2844 | 76 static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r, |
77 ngx_http_variable_value_t *v, uintptr_t data); | |
759 | 78 static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r, |
79 ngx_http_variable_value_t *v, uintptr_t data); | |
499 | 80 |
641 | 81 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
82 ngx_http_variable_value_t *v, uintptr_t data); | |
83 static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
84 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
|
85 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
|
86 ngx_http_variable_value_t *v, uintptr_t data); |
641 | 87 static ngx_int_t ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
88 ngx_http_variable_value_t *v, uintptr_t data); | |
89 static ngx_int_t ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
90 ngx_http_variable_value_t *v, uintptr_t data); | |
91 static ngx_int_t ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
92 ngx_http_variable_value_t *v, uintptr_t data); | |
93 static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
94 ngx_http_variable_value_t *v, uintptr_t data); | |
95 | |
1329 | 96 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r, |
97 ngx_http_variable_value_t *v, uintptr_t data); | |
2011 | 98 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, |
99 ngx_http_variable_value_t *v, uintptr_t data); | |
2249 | 100 static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r, |
101 ngx_http_variable_value_t *v, uintptr_t data); | |
499 | 102 |
509 | 103 /* |
104 * TODO: | |
105 * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED | |
106 * REMOTE_HOST (null), REMOTE_IDENT (null), | |
107 * SERVER_SOFTWARE | |
108 * | |
571 | 109 * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner) |
509 | 110 */ |
499 | 111 |
641 | 112 /* |
113 * the $http_host, $http_user_agent, $http_referer, $http_via, | |
114 * and $http_x_forwarded_for variables may be handled by generic | |
4572
67653855682e
Fixed spelling in multiline C comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4558
diff
changeset
|
115 * ngx_http_variable_unknown_header_in(), but for performance reasons |
641 | 116 * they are handled using dedicated entries |
117 */ | |
118 | |
509 | 119 static ngx_http_variable_t ngx_http_core_variables[] = { |
120 | |
637 | 121 { ngx_string("http_host"), NULL, ngx_http_variable_header, |
533 | 122 offsetof(ngx_http_request_t, headers_in.host), 0, 0 }, |
499 | 123 |
637 | 124 { ngx_string("http_user_agent"), NULL, ngx_http_variable_header, |
533 | 125 offsetof(ngx_http_request_t, headers_in.user_agent), 0, 0 }, |
509 | 126 |
637 | 127 { ngx_string("http_referer"), NULL, ngx_http_variable_header, |
533 | 128 offsetof(ngx_http_request_t, headers_in.referer), 0, 0 }, |
499 | 129 |
130 #if (NGX_HTTP_GZIP) | |
637 | 131 { ngx_string("http_via"), NULL, ngx_http_variable_header, |
533 | 132 offsetof(ngx_http_request_t, headers_in.via), 0, 0 }, |
499 | 133 #endif |
134 | |
1113
f1d7cf0f68e3
optimize $http_x_forwarded_for
Igor Sysoev <igor@sysoev.ru>
parents:
983
diff
changeset
|
135 #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP) |
637 | 136 { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_header, |
533 | 137 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 }, |
499 | 138 #endif |
139 | |
637 | 140 { ngx_string("http_cookie"), NULL, ngx_http_variable_headers, |
533 | 141 offsetof(ngx_http_request_t, headers_in.cookies), 0, 0 }, |
515 | 142 |
637 | 143 { ngx_string("content_length"), NULL, ngx_http_variable_header, |
533 | 144 offsetof(ngx_http_request_t, headers_in.content_length), 0, 0 }, |
509 | 145 |
637 | 146 { ngx_string("content_type"), NULL, ngx_http_variable_header, |
533 | 147 offsetof(ngx_http_request_t, headers_in.content_type), 0, 0 }, |
509 | 148 |
637 | 149 { ngx_string("host"), NULL, ngx_http_variable_host, 0, 0, 0 }, |
509 | 150 |
982 | 151 { ngx_string("binary_remote_addr"), NULL, |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
152 ngx_http_variable_binary_remote_addr, 0, 0, 0 }, |
982 | 153 |
637 | 154 { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 }, |
499 | 155 |
637 | 156 { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 }, |
509 | 157 |
637 | 158 { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 }, |
509 | 159 |
637 | 160 { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 }, |
509 | 161 |
637 | 162 { ngx_string("server_protocol"), NULL, ngx_http_variable_request, |
533 | 163 offsetof(ngx_http_request_t, http_protocol), 0, 0 }, |
509 | 164 |
731 | 165 { ngx_string("scheme"), NULL, ngx_http_variable_scheme, 0, 0, 0 }, |
166 | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
167 { 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
|
168 |
637 | 169 { ngx_string("request_uri"), NULL, ngx_http_variable_request, |
533 | 170 offsetof(ngx_http_request_t, unparsed_uri), 0, 0 }, |
499 | 171 |
637 | 172 { ngx_string("uri"), NULL, ngx_http_variable_request, |
173 offsetof(ngx_http_request_t, uri), | |
1565 | 174 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
637 | 175 |
176 { ngx_string("document_uri"), NULL, ngx_http_variable_request, | |
573 | 177 offsetof(ngx_http_request_t, uri), |
1565 | 178 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
573 | 179 |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
180 { ngx_string("request"), NULL, ngx_http_variable_request_line, 0, 0, 0 }, |
569 | 181 |
637 | 182 { ngx_string("document_root"), NULL, |
1565 | 183 ngx_http_variable_document_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 184 |
2259 | 185 { ngx_string("realpath_root"), NULL, |
186 ngx_http_variable_realpath_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
187 | |
637 | 188 { ngx_string("query_string"), NULL, ngx_http_variable_request, |
509 | 189 offsetof(ngx_http_request_t, args), |
1565 | 190 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
499 | 191 |
1350 | 192 { ngx_string("args"), |
193 ngx_http_variable_request_set, | |
194 ngx_http_variable_request, | |
589 | 195 offsetof(ngx_http_request_t, args), |
1565 | 196 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
589 | 197 |
1351 | 198 { ngx_string("is_args"), NULL, ngx_http_variable_is_args, |
1565 | 199 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
1351 | 200 |
637 | 201 { ngx_string("request_filename"), NULL, |
202 ngx_http_variable_request_filename, 0, | |
1565 | 203 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 204 |
1811 | 205 { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 }, |
509 | 206 |
637 | 207 { ngx_string("request_method"), NULL, |
3463
0904bd7d5b37
make $request_method non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3451
diff
changeset
|
208 ngx_http_variable_request_method, 0, |
0904bd7d5b37
make $request_method non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3451
diff
changeset
|
209 NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
509 | 210 |
637 | 211 { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 }, |
509 | 212 |
637 | 213 { ngx_string("body_bytes_sent"), NULL, ngx_http_variable_body_bytes_sent, |
611 | 214 0, 0, 0 }, |
215 | |
637 | 216 { ngx_string("request_completion"), NULL, |
217 ngx_http_variable_request_completion, | |
629 | 218 0, 0, 0 }, |
219 | |
2844 | 220 { ngx_string("request_body"), NULL, |
221 ngx_http_variable_request_body, | |
222 0, 0, 0 }, | |
223 | |
759 | 224 { ngx_string("request_body_file"), NULL, |
225 ngx_http_variable_request_body_file, | |
226 0, 0, 0 }, | |
227 | |
641 | 228 { ngx_string("sent_http_content_type"), NULL, |
229 ngx_http_variable_sent_content_type, 0, 0, 0 }, | |
230 | |
231 { ngx_string("sent_http_content_length"), NULL, | |
232 ngx_http_variable_sent_content_length, 0, 0, 0 }, | |
233 | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
234 { ngx_string("sent_http_location"), NULL, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
235 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
|
236 |
641 | 237 { ngx_string("sent_http_last_modified"), NULL, |
238 ngx_http_variable_sent_last_modified, 0, 0, 0 }, | |
239 | |
240 { ngx_string("sent_http_connection"), NULL, | |
241 ngx_http_variable_sent_connection, 0, 0, 0 }, | |
242 | |
243 { ngx_string("sent_http_keep_alive"), NULL, | |
244 ngx_http_variable_sent_keep_alive, 0, 0, 0 }, | |
245 | |
246 { ngx_string("sent_http_transfer_encoding"), NULL, | |
247 ngx_http_variable_sent_transfer_encoding, 0, 0, 0 }, | |
248 | |
249 { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_headers, | |
250 offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 }, | |
251 | |
637 | 252 { ngx_string("limit_rate"), ngx_http_variable_request_set_size, |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
253 ngx_http_variable_request_get_size, |
637 | 254 offsetof(ngx_http_request_t, limit_rate), |
1565 | 255 NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 }, |
637 | 256 |
1329 | 257 { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version, |
258 0, 0, 0 }, | |
259 | |
2011 | 260 { ngx_string("hostname"), NULL, ngx_http_variable_hostname, |
261 0, 0, 0 }, | |
262 | |
2249 | 263 { ngx_string("pid"), NULL, ngx_http_variable_pid, |
264 0, 0, 0 }, | |
265 | |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
266 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
267 { 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
|
268 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
|
269 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
270 { 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
|
271 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
|
272 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
273 { 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
|
274 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
|
275 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
276 { 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
|
277 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
|
278 #endif |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
279 |
637 | 280 { ngx_null_string, NULL, NULL, 0, 0, 0 } |
499 | 281 }; |
282 | |
283 | |
577 | 284 ngx_http_variable_value_t ngx_http_variable_null_value = |
285 ngx_http_variable(""); | |
286 ngx_http_variable_value_t ngx_http_variable_true_value = | |
287 ngx_http_variable("1"); | |
288 | |
289 | |
499 | 290 ngx_http_variable_t * |
509 | 291 ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags) |
292 { | |
611 | 293 ngx_int_t rc; |
509 | 294 ngx_uint_t i; |
611 | 295 ngx_hash_key_t *key; |
509 | 296 ngx_http_variable_t *v; |
297 ngx_http_core_main_conf_t *cmcf; | |
298 | |
299 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
300 | |
611 | 301 key = cmcf->variables_keys->keys.elts; |
302 for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) { | |
303 if (name->len != key[i].key.len | |
304 || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0) | |
509 | 305 { |
306 continue; | |
307 } | |
308 | |
611 | 309 v = key[i].value; |
310 | |
1565 | 311 if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) { |
509 | 312 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
313 "the duplicate \"%V\" variable", name); | |
314 return NULL; | |
315 } | |
316 | |
611 | 317 return v; |
509 | 318 } |
319 | |
611 | 320 v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t)); |
509 | 321 if (v == NULL) { |
322 return NULL; | |
323 } | |
324 | |
325 v->name.len = name->len; | |
2049 | 326 v->name.data = ngx_pnalloc(cf->pool, name->len); |
509 | 327 if (v->name.data == NULL) { |
328 return NULL; | |
329 } | |
330 | |
2135 | 331 ngx_strlow(v->name.data, name->data, name->len); |
509 | 332 |
637 | 333 v->set_handler = NULL; |
334 v->get_handler = NULL; | |
509 | 335 v->data = 0; |
336 v->flags = flags; | |
533 | 337 v->index = 0; |
509 | 338 |
611 | 339 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0); |
340 | |
341 if (rc == NGX_ERROR) { | |
342 return NULL; | |
343 } | |
344 | |
345 if (rc == NGX_BUSY) { | |
346 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
347 "conflicting variable name \"%V\"", name); | |
348 return NULL; | |
349 } | |
350 | |
509 | 351 return v; |
352 } | |
353 | |
354 | |
355 ngx_int_t | |
356 ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name) | |
499 | 357 { |
501 | 358 ngx_uint_t i; |
359 ngx_http_variable_t *v; | |
499 | 360 ngx_http_core_main_conf_t *cmcf; |
361 | |
362 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
363 | |
501 | 364 v = cmcf->variables.elts; |
365 | |
366 if (v == NULL) { | |
499 | 367 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
|
368 sizeof(ngx_http_variable_t)) |
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2533
diff
changeset
|
369 != NGX_OK) |
499 | 370 { |
509 | 371 return NGX_ERROR; |
499 | 372 } |
501 | 373 |
374 } else { | |
375 for (i = 0; i < cmcf->variables.nelts; i++) { | |
376 if (name->len != v[i].name.len | |
377 || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0) | |
378 { | |
379 continue; | |
380 } | |
381 | |
509 | 382 return i; |
501 | 383 } |
499 | 384 } |
385 | |
501 | 386 v = ngx_array_push(&cmcf->variables); |
387 if (v == NULL) { | |
509 | 388 return NGX_ERROR; |
499 | 389 } |
390 | |
501 | 391 v->name.len = name->len; |
2049 | 392 v->name.data = ngx_pnalloc(cf->pool, name->len); |
501 | 393 if (v->name.data == NULL) { |
509 | 394 return NGX_ERROR; |
501 | 395 } |
499 | 396 |
2135 | 397 ngx_strlow(v->name.data, name->data, name->len); |
501 | 398 |
637 | 399 v->set_handler = NULL; |
400 v->get_handler = NULL; | |
501 | 401 v->data = 0; |
509 | 402 v->flags = 0; |
533 | 403 v->index = cmcf->variables.nelts - 1; |
501 | 404 |
4540
cab9aa79256c
Slight optimization in ngx_http_get_variable_index().
Ruslan Ermilov <ru@nginx.com>
parents:
4470
diff
changeset
|
405 return v->index; |
499 | 406 } |
407 | |
408 | |
409 ngx_http_variable_value_t * | |
410 ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index) | |
411 { | |
501 | 412 ngx_http_variable_t *v; |
499 | 413 ngx_http_core_main_conf_t *cmcf; |
414 | |
415 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
416 | |
553 | 417 if (cmcf->variables.nelts <= index) { |
499 | 418 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, |
419 "unknown variable index: %d", index); | |
420 return NULL; | |
421 } | |
422 | |
573 | 423 if (r->variables[index].not_found || r->variables[index].valid) { |
424 return &r->variables[index]; | |
501 | 425 } |
499 | 426 |
501 | 427 v = cmcf->variables.elts; |
499 | 428 |
637 | 429 if (v[index].get_handler(r, &r->variables[index], v[index].data) |
430 == NGX_OK) | |
431 { | |
1565 | 432 if (v[index].flags & NGX_HTTP_VAR_NOCACHEABLE) { |
433 r->variables[index].no_cacheable = 1; | |
499 | 434 } |
573 | 435 |
436 return &r->variables[index]; | |
499 | 437 } |
438 | |
657 | 439 r->variables[index].valid = 0; |
440 r->variables[index].not_found = 1; | |
441 | |
798 | 442 return NULL; |
573 | 443 } |
444 | |
445 | |
446 ngx_http_variable_value_t * | |
447 ngx_http_get_flushed_variable(ngx_http_request_t *r, ngx_uint_t index) | |
448 { | |
1150 | 449 ngx_http_variable_value_t *v; |
573 | 450 |
451 v = &r->variables[index]; | |
452 | |
4470
d9bf6caf0371
Variables: honor no_cacheable for not_found variables.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
453 if (v->valid || v->not_found) { |
1565 | 454 if (!v->no_cacheable) { |
573 | 455 return v; |
456 } | |
457 | |
458 v->valid = 0; | |
459 v->not_found = 0; | |
509 | 460 } |
501 | 461 |
573 | 462 return ngx_http_get_indexed_variable(r, index); |
499 | 463 } |
464 | |
465 | |
466 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
|
467 ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key) |
499 | 468 { |
501 | 469 ngx_http_variable_t *v; |
573 | 470 ngx_http_variable_value_t *vv; |
499 | 471 ngx_http_core_main_conf_t *cmcf; |
472 | |
473 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
474 | |
611 | 475 v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len); |
499 | 476 |
611 | 477 if (v) { |
478 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
|
479 return ngx_http_get_flushed_variable(r, v->index); |
519 | 480 |
481 } else { | |
499 | 482 |
573 | 483 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); |
501 | 484 |
637 | 485 if (vv && v->get_handler(r, vv, v->data) == NGX_OK) { |
573 | 486 return vv; |
487 } | |
509 | 488 |
573 | 489 return NULL; |
490 } | |
509 | 491 } |
492 | |
493 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t)); | |
494 if (vv == NULL) { | |
495 return NULL; | |
496 } | |
497 | |
573 | 498 if (ngx_strncmp(name->data, "http_", 5) == 0) { |
499 | 499 |
577 | 500 if (ngx_http_variable_unknown_header_in(r, vv, (uintptr_t) name) |
501 == NGX_OK) | |
502 { | |
503 return vv; | |
504 } | |
505 | |
506 return NULL; | |
507 } | |
508 | |
509 if (ngx_strncmp(name->data, "sent_http_", 10) == 0) { | |
510 | |
511 if (ngx_http_variable_unknown_header_out(r, vv, (uintptr_t) name) | |
512 == NGX_OK) | |
573 | 513 { |
514 return vv; | |
515 } | |
499 | 516 |
517 return NULL; | |
518 } | |
519 | |
3451
7a1958778351
fix $upstream_http_ variable prefix length
Igor Sysoev <igor@sysoev.ru>
parents:
3409
diff
changeset
|
520 if (ngx_strncmp(name->data, "upstream_http_", 14) == 0) { |
1162 | 521 |
522 if (ngx_http_upstream_header_variable(r, vv, (uintptr_t) name) | |
523 == NGX_OK) | |
524 { | |
525 return vv; | |
526 } | |
527 | |
528 return NULL; | |
529 } | |
530 | |
2307 | 531 if (ngx_strncmp(name->data, "cookie_", 7) == 0) { |
532 | |
2359
4fee4ebbfb0b
$cookie_... variable did not for SSI and perl
Igor Sysoev <igor@sysoev.ru>
parents:
2333
diff
changeset
|
533 if (ngx_http_variable_cookie(r, vv, (uintptr_t) name) == NGX_OK) { |
2307 | 534 return vv; |
535 } | |
536 | |
537 return NULL; | |
538 } | |
539 | |
2137 | 540 if (ngx_strncmp(name->data, "arg_", 4) == 0) { |
541 | |
542 if (ngx_http_variable_argument(r, vv, (uintptr_t) name) == NGX_OK) { | |
543 return vv; | |
544 } | |
545 | |
546 return NULL; | |
547 } | |
548 | |
635 | 549 vv->not_found = 1; |
573 | 550 |
501 | 551 return vv; |
499 | 552 } |
553 | |
554 | |
573 | 555 static ngx_int_t |
556 ngx_http_variable_request(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
557 uintptr_t data) | |
558 { | |
559 ngx_str_t *s; | |
560 | |
561 s = (ngx_str_t *) ((char *) r + data); | |
562 | |
563 if (s->data) { | |
564 v->len = s->len; | |
565 v->valid = 1; | |
1565 | 566 v->no_cacheable = 0; |
573 | 567 v->not_found = 0; |
568 v->data = s->data; | |
569 | |
570 } else { | |
571 v->not_found = 1; | |
572 } | |
573 | |
574 return NGX_OK; | |
575 } | |
576 | |
577 | |
637 | 578 static void |
1350 | 579 ngx_http_variable_request_set(ngx_http_request_t *r, |
580 ngx_http_variable_value_t *v, uintptr_t data) | |
581 { | |
582 ngx_str_t *s; | |
583 | |
584 s = (ngx_str_t *) ((char *) r + data); | |
585 | |
586 s->len = v->len; | |
587 s->data = v->data; | |
588 } | |
589 | |
590 | |
3282
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
591 static ngx_int_t |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
592 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
|
593 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
|
594 { |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
595 size_t *sp; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
596 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
597 sp = (size_t *) ((char *) r + data); |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
598 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
599 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
|
600 if (v->data == NULL) { |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
601 return NGX_ERROR; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
602 } |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
603 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
604 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
|
605 v->valid = 1; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
606 v->no_cacheable = 0; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
607 v->not_found = 0; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
608 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
609 return NGX_OK; |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
610 } |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
611 |
c76b7a7959d5
fix segfault if $limit_rate was logged
Igor Sysoev <igor@sysoev.ru>
parents:
3268
diff
changeset
|
612 |
1350 | 613 static void |
637 | 614 ngx_http_variable_request_set_size(ngx_http_request_t *r, |
615 ngx_http_variable_value_t *v, uintptr_t data) | |
616 { | |
617 ssize_t s, *sp; | |
618 ngx_str_t val; | |
619 | |
1310
33d6c994a0b2
Sun Studio on sparc uses different bit order
Igor Sysoev <igor@sysoev.ru>
parents:
1191
diff
changeset
|
620 val.len = v->len; |
637 | 621 val.data = v->data; |
622 | |
623 s = ngx_parse_size(&val); | |
624 | |
625 if (s == NGX_ERROR) { | |
626 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
627 "invalid size \"%V\"", &val); | |
628 return; | |
629 } | |
630 | |
631 sp = (ssize_t *) ((char *) r + data); | |
632 | |
633 *sp = s; | |
634 | |
635 return; | |
636 } | |
637 | |
638 | |
573 | 639 static ngx_int_t |
640 ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
641 uintptr_t data) | |
515 | 642 { |
573 | 643 ngx_table_elt_t *h; |
644 | |
645 h = *(ngx_table_elt_t **) ((char *) r + data); | |
646 | |
647 if (h) { | |
648 v->len = h->value.len; | |
649 v->valid = 1; | |
1565 | 650 v->no_cacheable = 0; |
573 | 651 v->not_found = 0; |
652 v->data = h->value.data; | |
653 | |
654 } else { | |
655 v->not_found = 1; | |
656 } | |
657 | |
658 return NGX_OK; | |
659 } | |
660 | |
661 | |
662 static ngx_int_t | |
663 ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
664 uintptr_t data) | |
665 { | |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
666 size_t len; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
667 u_char *p, *end; |
667 | 668 ngx_uint_t i, n; |
573 | 669 ngx_array_t *a; |
670 ngx_table_elt_t **h; | |
515 | 671 |
672 a = (ngx_array_t *) ((char *) r + data); | |
673 | |
667 | 674 n = a->nelts; |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
675 h = a->elts; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
676 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
677 len = 0; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
678 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
679 for (i = 0; i < n; i++) { |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
680 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
681 if (h[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
|
682 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
683 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
684 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
685 len += h[i]->value.len + sizeof("; ") - 1; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
686 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
687 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
688 if (len == 0) { |
573 | 689 v->not_found = 1; |
690 return NGX_OK; | |
515 | 691 } |
692 | |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
693 len -= sizeof("; ") - 1; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
694 |
573 | 695 v->valid = 1; |
1565 | 696 v->no_cacheable = 0; |
573 | 697 v->not_found = 0; |
515 | 698 |
667 | 699 if (n == 1) { |
573 | 700 v->len = (*h)->value.len; |
701 v->data = (*h)->value.data; | |
515 | 702 |
573 | 703 return NGX_OK; |
515 | 704 } |
705 | |
2049 | 706 p = ngx_pnalloc(r->pool, len); |
573 | 707 if (p == NULL) { |
708 return NGX_ERROR; | |
709 } | |
710 | |
711 v->len = len; | |
712 v->data = p; | |
515 | 713 |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
714 end = p + len; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
715 |
515 | 716 for (i = 0; /* void */ ; i++) { |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
717 |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
718 if (h[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
|
719 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
720 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
721 |
573 | 722 p = ngx_copy(p, h[i]->value.data, h[i]->value.len); |
515 | 723 |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
724 if (p == end) { |
515 | 725 break; |
726 } | |
727 | |
728 *p++ = ';'; *p++ = ' '; | |
729 } | |
730 | |
573 | 731 return NGX_OK; |
515 | 732 } |
733 | |
734 | |
573 | 735 static ngx_int_t |
577 | 736 ngx_http_variable_unknown_header_in(ngx_http_request_t *r, |
737 ngx_http_variable_value_t *v, uintptr_t data) | |
738 { | |
739 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, | |
740 &r->headers_in.headers.part, | |
741 sizeof("http_") - 1); | |
742 } | |
743 | |
744 | |
745 static ngx_int_t | |
746 ngx_http_variable_unknown_header_out(ngx_http_request_t *r, | |
573 | 747 ngx_http_variable_value_t *v, uintptr_t data) |
499 | 748 { |
577 | 749 return ngx_http_variable_unknown_header(v, (ngx_str_t *) data, |
750 &r->headers_out.headers.part, | |
751 sizeof("sent_http_") - 1); | |
752 } | |
501 | 753 |
577 | 754 |
1162 | 755 ngx_int_t |
577 | 756 ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var, |
757 ngx_list_part_t *part, size_t prefix) | |
758 { | |
573 | 759 u_char ch; |
760 ngx_uint_t i, n; | |
761 ngx_table_elt_t *header; | |
499 | 762 |
763 header = part->elts; | |
764 | |
765 for (i = 0; /* void */ ; i++) { | |
766 | |
767 if (i >= part->nelts) { | |
768 if (part->next == NULL) { | |
769 break; | |
770 } | |
771 | |
772 part = part->next; | |
773 header = part->elts; | |
774 i = 0; | |
775 } | |
776 | |
4334
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
777 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
|
778 continue; |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
779 } |
f8881d301d62
Fixed: some of $sent_http_* variables may contain header entries that actually
Valentin Bartenev <vbart@nginx.com>
parents:
4332
diff
changeset
|
780 |
577 | 781 for (n = 0; n + prefix < var->len && n < header[i].key.len; n++) { |
499 | 782 ch = header[i].key.data[n]; |
783 | |
509 | 784 if (ch >= 'A' && ch <= 'Z') { |
785 ch |= 0x20; | |
499 | 786 |
787 } else if (ch == '-') { | |
788 ch = '_'; | |
789 } | |
790 | |
577 | 791 if (var->data[n + prefix] != ch) { |
499 | 792 break; |
793 } | |
794 } | |
795 | |
742
75d767d32624
nonexistent $sent_http_content has value of $sent_http_content_length or so
Igor Sysoev <igor@sysoev.ru>
parents:
732
diff
changeset
|
796 if (n + prefix == var->len && n == header[i].key.len) { |
573 | 797 v->len = header[i].value.len; |
798 v->valid = 1; | |
1565 | 799 v->no_cacheable = 0; |
573 | 800 v->not_found = 0; |
801 v->data = header[i].value.data; | |
499 | 802 |
573 | 803 return NGX_OK; |
499 | 804 } |
805 } | |
806 | |
573 | 807 v->not_found = 1; |
808 | |
809 return NGX_OK; | |
509 | 810 } |
811 | |
812 | |
573 | 813 static ngx_int_t |
3144
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
814 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
|
815 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
|
816 { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
817 u_char *p, *s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
818 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
819 s = r->request_line.data; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
820 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
821 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
822 s = r->request_start; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
823 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
824 if (s == NULL) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
825 v->not_found = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
826 return NGX_OK; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
827 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
828 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
829 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
|
830 if (*p == CR || *p == LF) { |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
831 break; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
832 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
833 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
834 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
835 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
|
836 r->request_line.data = s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
837 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
838 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
839 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
|
840 v->valid = 1; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
841 v->no_cacheable = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
842 v->not_found = 0; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
843 v->data = s; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
844 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
845 return NGX_OK; |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
846 } |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
847 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
848 |
ecbfc3396c42
allow to log invalid $request in access_log always,
Igor Sysoev <igor@sysoev.ru>
parents:
2878
diff
changeset
|
849 static ngx_int_t |
2307 | 850 ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
851 uintptr_t data) | |
852 { | |
853 ngx_str_t *name = (ngx_str_t *) data; | |
854 | |
855 ngx_str_t cookie, s; | |
856 | |
857 s.len = name->len - (sizeof("cookie_") - 1); | |
858 s.data = name->data + sizeof("cookie_") - 1; | |
859 | |
860 if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &s, &cookie) | |
861 == NGX_DECLINED) | |
862 { | |
863 v->not_found = 1; | |
864 return NGX_OK; | |
865 } | |
866 | |
867 v->len = cookie.len; | |
868 v->valid = 1; | |
869 v->no_cacheable = 0; | |
870 v->not_found = 0; | |
871 v->data = cookie.data; | |
872 | |
873 return NGX_OK; | |
874 } | |
875 | |
876 | |
877 static ngx_int_t | |
2137 | 878 ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
879 uintptr_t data) | |
880 { | |
881 ngx_str_t *name = (ngx_str_t *) data; | |
882 | |
2415 | 883 u_char *arg; |
884 size_t len; | |
885 ngx_str_t value; | |
2137 | 886 |
2415 | 887 len = name->len - (sizeof("arg_") - 1); |
888 arg = name->data + sizeof("arg_") - 1; | |
889 | |
890 if (ngx_http_arg(r, arg, len, &value) != NGX_OK) { | |
2137 | 891 v->not_found = 1; |
892 return NGX_OK; | |
893 } | |
894 | |
2415 | 895 v->data = value.data; |
896 v->len = value.len; | |
897 v->valid = 1; | |
898 v->no_cacheable = 0; | |
899 v->not_found = 0; | |
2137 | 900 |
901 return NGX_OK; | |
902 } | |
903 | |
904 | |
4545
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
905 #if (NGX_HAVE_TCP_INFO) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
906 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
907 static ngx_int_t |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
908 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
|
909 uintptr_t data) |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
910 { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
911 struct tcp_info ti; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
912 socklen_t len; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
913 uint32_t value; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
914 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
915 len = sizeof(struct tcp_info); |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
916 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
|
917 v->not_found = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
918 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
919 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
920 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
921 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
|
922 if (v->data == NULL) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
923 return NGX_ERROR; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
924 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
925 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
926 switch (data) { |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
927 case 0: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
928 value = ti.tcpi_rtt; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
929 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
930 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
931 case 1: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
932 value = ti.tcpi_rttvar; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
933 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
934 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
935 case 2: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
936 value = ti.tcpi_snd_cwnd; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
937 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
938 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
939 case 3: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
940 value = ti.tcpi_rcv_space; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
941 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
942 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
943 /* suppress warning */ |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
944 default: |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
945 value = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
946 break; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
947 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
948 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
949 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
|
950 v->valid = 1; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
951 v->no_cacheable = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
952 v->not_found = 0; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
953 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
954 return NGX_OK; |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
955 } |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
956 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
957 #endif |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
958 |
ba39af7274ed
Implemented $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, and
Ruslan Ermilov <ru@nginx.com>
parents:
4540
diff
changeset
|
959 |
2137 | 960 static ngx_int_t |
573 | 961 ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
962 uintptr_t data) | |
509 | 963 { |
1811 | 964 ngx_http_core_srv_conf_t *cscf; |
965 | |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
966 if (r->headers_in.server.len) { |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
967 v->len = r->headers_in.server.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
968 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
|
969 |
a6fe6bedb9e3
fix segfault when $host is used and
Igor Sysoev <igor@sysoev.ru>
parents:
864
diff
changeset
|
970 } else { |
2007
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
971 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
|
972 |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
973 v->len = cscf->server_name.len; |
b9de93d804ea
*) host in request line has priority
Igor Sysoev <igor@sysoev.ru>
parents:
1811
diff
changeset
|
974 v->data = cscf->server_name.data; |
509 | 975 } |
976 | |
573 | 977 v->valid = 1; |
1565 | 978 v->no_cacheable = 0; |
573 | 979 v->not_found = 0; |
509 | 980 |
573 | 981 return NGX_OK; |
499 | 982 } |
983 | |
984 | |
573 | 985 static ngx_int_t |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
986 ngx_http_variable_binary_remote_addr(ngx_http_request_t *r, |
573 | 987 ngx_http_variable_value_t *v, uintptr_t data) |
499 | 988 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
989 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
990 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
991 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
992 #endif |
982 | 993 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
994 switch (r->connection->sockaddr->sa_family) { |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
995 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
996 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
997 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
998 sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; |
982 | 999 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1000 v->len = sizeof(struct in6_addr); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1001 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1002 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1003 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
|
1004 v->data = sin6->sin6_addr.s6_addr; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1005 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1006 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1007 #endif |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1008 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1009 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1010 sin = (struct sockaddr_in *) r->connection->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1011 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1012 v->len = sizeof(in_addr_t); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1013 v->valid = 1; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1014 v->no_cacheable = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1015 v->not_found = 0; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1016 v->data = (u_char *) &sin->sin_addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1017 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1018 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1019 } |
982 | 1020 |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1021 return NGX_OK; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1022 } |
982 | 1023 |
1024 | |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1025 static ngx_int_t |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1026 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
|
1027 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
|
1028 { |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1029 v->len = r->connection->addr_text.len; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1030 v->valid = 1; |
1565 | 1031 v->no_cacheable = 0; |
983
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1032 v->not_found = 0; |
7a8ca436d611
ngx_http_variable_binary_remote_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
982
diff
changeset
|
1033 v->data = r->connection->addr_text.data; |
499 | 1034 |
573 | 1035 return NGX_OK; |
499 | 1036 } |
1037 | |
1038 | |
573 | 1039 static ngx_int_t |
1040 ngx_http_variable_remote_port(ngx_http_request_t *r, | |
1041 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1042 { |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1043 ngx_uint_t port; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1044 struct sockaddr_in *sin; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1045 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1046 struct sockaddr_in6 *sin6; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1047 #endif |
509 | 1048 |
573 | 1049 v->len = 0; |
1050 v->valid = 1; | |
1565 | 1051 v->no_cacheable = 0; |
573 | 1052 v->not_found = 0; |
509 | 1053 |
2049 | 1054 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); |
573 | 1055 if (v->data == NULL) { |
1056 return NGX_ERROR; | |
509 | 1057 } |
1058 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1059 switch (r->connection->sockaddr->sa_family) { |
577 | 1060 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1061 #if (NGX_HAVE_INET6) |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1062 case AF_INET6: |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1063 sin6 = (struct sockaddr_in6 *) r->connection->sockaddr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1064 port = ntohs(sin6->sin6_port); |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1065 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1066 #endif |
577 | 1067 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1068 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1069 sin = (struct sockaddr_in *) r->connection->sockaddr; |
509 | 1070 port = ntohs(sin->sin_port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1071 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1072 } |
577 | 1073 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1074 if (port > 0 && port < 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1075 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
509 | 1076 } |
1077 | |
573 | 1078 return NGX_OK; |
509 | 1079 } |
1080 | |
1081 | |
573 | 1082 static ngx_int_t |
1083 ngx_http_variable_server_addr(ngx_http_request_t *r, | |
1084 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1085 { |
1805 | 1086 ngx_str_t s; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1087 u_char addr[NGX_SOCKADDR_STRLEN]; |
499 | 1088 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1089 s.len = NGX_SOCKADDR_STRLEN; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1090 s.data = addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1091 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1092 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
|
1093 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1094 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1095 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1096 s.data = ngx_pnalloc(r->pool, s.len); |
1805 | 1097 if (s.data == NULL) { |
573 | 1098 return NGX_ERROR; |
509 | 1099 } |
1100 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1101 ngx_memcpy(s.data, addr, s.len); |
509 | 1102 |
1805 | 1103 v->len = s.len; |
573 | 1104 v->valid = 1; |
1565 | 1105 v->no_cacheable = 0; |
573 | 1106 v->not_found = 0; |
1805 | 1107 v->data = s.data; |
499 | 1108 |
573 | 1109 return NGX_OK; |
499 | 1110 } |
1111 | |
1112 | |
573 | 1113 static ngx_int_t |
1114 ngx_http_variable_server_port(ngx_http_request_t *r, | |
1115 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1116 { |
2533 | 1117 ngx_uint_t port; |
1118 struct sockaddr_in *sin; | |
1119 #if (NGX_HAVE_INET6) | |
1120 struct sockaddr_in6 *sin6; | |
1121 #endif | |
1122 | |
1123 v->len = 0; | |
573 | 1124 v->valid = 1; |
1565 | 1125 v->no_cacheable = 0; |
573 | 1126 v->not_found = 0; |
2533 | 1127 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1128 if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) { |
2533 | 1129 return NGX_ERROR; |
1130 } | |
1131 | |
1132 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); | |
1133 if (v->data == NULL) { | |
1134 return NGX_ERROR; | |
1135 } | |
1136 | |
1137 switch (r->connection->local_sockaddr->sa_family) { | |
1138 | |
1139 #if (NGX_HAVE_INET6) | |
1140 case AF_INET6: | |
1141 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr; | |
1142 port = ntohs(sin6->sin6_port); | |
1143 break; | |
1144 #endif | |
1145 | |
1146 default: /* AF_INET */ | |
1147 sin = (struct sockaddr_in *) r->connection->local_sockaddr; | |
1148 port = ntohs(sin->sin_port); | |
1149 break; | |
1150 } | |
1151 | |
1152 if (port > 0 && port < 65536) { | |
1153 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; | |
1154 } | |
509 | 1155 |
573 | 1156 return NGX_OK; |
509 | 1157 } |
1158 | |
1159 | |
573 | 1160 static ngx_int_t |
731 | 1161 ngx_http_variable_scheme(ngx_http_request_t *r, |
1162 ngx_http_variable_value_t *v, uintptr_t data) | |
1163 { | |
1164 #if (NGX_HTTP_SSL) | |
1165 | |
1166 if (r->connection->ssl) { | |
1167 v->len = sizeof("https") - 1; | |
1168 v->valid = 1; | |
1565 | 1169 v->no_cacheable = 0; |
731 | 1170 v->not_found = 0; |
732 | 1171 v->data = (u_char *) "https"; |
731 | 1172 |
1173 return NGX_OK; | |
1174 } | |
1175 | |
1176 #endif | |
1177 | |
1178 v->len = sizeof("http") - 1; | |
1179 v->valid = 1; | |
1565 | 1180 v->no_cacheable = 0; |
731 | 1181 v->not_found = 0; |
732 | 1182 v->data = (u_char *) "http"; |
731 | 1183 |
1184 return NGX_OK; | |
1185 } | |
1186 | |
1187 | |
1188 static ngx_int_t | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1189 ngx_http_variable_https(ngx_http_request_t *r, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1190 ngx_http_variable_value_t *v, uintptr_t data) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1191 { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1192 #if (NGX_HTTP_SSL) |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1193 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1194 if (r->connection->ssl) { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1195 v->len = sizeof("on") - 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1196 v->valid = 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1197 v->no_cacheable = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1198 v->not_found = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1199 v->data = (u_char *) "on"; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1200 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1201 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1202 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1203 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1204 #endif |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1205 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1206 *v = ngx_http_variable_null_value; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1207 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1208 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1209 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1210 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1211 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1212 static ngx_int_t |
1351 | 1213 ngx_http_variable_is_args(ngx_http_request_t *r, |
1214 ngx_http_variable_value_t *v, uintptr_t data) | |
1215 { | |
1216 v->valid = 1; | |
1565 | 1217 v->no_cacheable = 0; |
1351 | 1218 v->not_found = 0; |
1219 | |
1220 if (r->args.len == 0) { | |
1221 v->len = 0; | |
1222 v->data = NULL; | |
1223 return NGX_OK; | |
1224 } | |
1225 | |
1226 v->len = 1; | |
1227 v->data = (u_char *) "?"; | |
1228 | |
1229 return NGX_OK; | |
1230 } | |
1231 | |
1232 | |
1233 static ngx_int_t | |
573 | 1234 ngx_http_variable_document_root(ngx_http_request_t *r, |
1235 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1236 { |
671 | 1237 ngx_str_t path; |
573 | 1238 ngx_http_core_loc_conf_t *clcf; |
509 | 1239 |
1240 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1241 | |
671 | 1242 if (clcf->root_lengths == NULL) { |
1243 v->len = clcf->root.len; | |
1244 v->valid = 1; | |
1565 | 1245 v->no_cacheable = 0; |
671 | 1246 v->not_found = 0; |
1247 v->data = clcf->root.data; | |
1248 | |
1249 } else { | |
1250 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0, | |
1251 clcf->root_values->elts) | |
1252 == NULL) | |
1253 { | |
1254 return NGX_ERROR; | |
1255 } | |
1256 | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2533
diff
changeset
|
1257 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { |
671 | 1258 return NGX_ERROR; |
1259 } | |
1260 | |
1261 v->len = path.len; | |
1262 v->valid = 1; | |
1565 | 1263 v->no_cacheable = 0; |
671 | 1264 v->not_found = 0; |
1265 v->data = path.data; | |
1266 } | |
509 | 1267 |
573 | 1268 return NGX_OK; |
509 | 1269 } |
1270 | |
1271 | |
573 | 1272 static ngx_int_t |
2259 | 1273 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1274 ngx_http_variable_value_t *v, uintptr_t data) | |
1275 { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1276 u_char *real; |
2259 | 1277 size_t len; |
1278 ngx_str_t path; | |
1279 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
|
1280 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1281 u_char buffer[NGX_MAX_PATH]; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1282 #endif |
2259 | 1283 |
1284 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1285 | |
1286 if (clcf->root_lengths == NULL) { | |
1287 path = clcf->root; | |
1288 | |
1289 } else { | |
1290 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1, | |
1291 clcf->root_values->elts) | |
1292 == NULL) | |
1293 { | |
1294 return NGX_ERROR; | |
1295 } | |
1296 | |
1297 path.data[path.len - 1] = '\0'; | |
1298 | |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2533
diff
changeset
|
1299 if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) { |
2259 | 1300 return NGX_ERROR; |
1301 } | |
1302 } | |
1303 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1304 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1305 real = buffer; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1306 #else |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1307 real = NULL; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1308 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1309 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1310 real = ngx_realpath(path.data, real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1311 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1312 if (real == NULL) { |
2259 | 1313 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1314 ngx_realpath_n " \"%s\" failed", path.data); | |
1315 return NGX_ERROR; | |
1316 } | |
1317 | |
1318 len = ngx_strlen(real); | |
1319 | |
1320 v->data = ngx_pnalloc(r->pool, len); | |
1321 if (v->data == NULL) { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1322 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1323 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1324 #endif |
2259 | 1325 return NGX_ERROR; |
1326 } | |
1327 | |
1328 v->len = len; | |
1329 v->valid = 1; | |
1330 v->no_cacheable = 0; | |
1331 v->not_found = 0; | |
1332 | |
1333 ngx_memcpy(v->data, real, len); | |
1334 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1335 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1336 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1337 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1338 |
2259 | 1339 return NGX_OK; |
1340 } | |
1341 | |
1342 | |
1343 static ngx_int_t | |
573 | 1344 ngx_http_variable_request_filename(ngx_http_request_t *r, |
1345 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1346 { |
773 | 1347 size_t root; |
573 | 1348 ngx_str_t path; |
499 | 1349 |
773 | 1350 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
573 | 1351 return NGX_ERROR; |
557 | 1352 } |
509 | 1353 |
557 | 1354 /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */ |
509 | 1355 |
573 | 1356 v->len = path.len - 1; |
1357 v->valid = 1; | |
1565 | 1358 v->no_cacheable = 0; |
573 | 1359 v->not_found = 0; |
1360 v->data = path.data; | |
499 | 1361 |
573 | 1362 return NGX_OK; |
499 | 1363 } |
1364 | |
1365 | |
573 | 1366 static ngx_int_t |
1811 | 1367 ngx_http_variable_server_name(ngx_http_request_t *r, |
1368 ngx_http_variable_value_t *v, uintptr_t data) | |
1369 { | |
1370 ngx_http_core_srv_conf_t *cscf; | |
1371 | |
1372 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1373 | |
1374 v->len = cscf->server_name.len; | |
1375 v->valid = 1; | |
1376 v->no_cacheable = 0; | |
1377 v->not_found = 0; | |
1378 v->data = cscf->server_name.data; | |
1379 | |
1380 return NGX_OK; | |
1381 } | |
1382 | |
1383 | |
1384 static ngx_int_t | |
573 | 1385 ngx_http_variable_request_method(ngx_http_request_t *r, |
1386 ngx_http_variable_value_t *v, uintptr_t data) | |
561 | 1387 { |
647 | 1388 if (r->main->method_name.data) { |
1389 v->len = r->main->method_name.len; | |
573 | 1390 v->valid = 1; |
1565 | 1391 v->no_cacheable = 0; |
573 | 1392 v->not_found = 0; |
647 | 1393 v->data = r->main->method_name.data; |
573 | 1394 |
1395 } else { | |
1396 v->not_found = 1; | |
561 | 1397 } |
1398 | |
573 | 1399 return NGX_OK; |
561 | 1400 } |
1401 | |
1402 | |
573 | 1403 static ngx_int_t |
1404 ngx_http_variable_remote_user(ngx_http_request_t *r, | |
1405 ngx_http_variable_value_t *v, uintptr_t data) | |
539 | 1406 { |
573 | 1407 ngx_int_t rc; |
539 | 1408 |
1409 rc = ngx_http_auth_basic_user(r); | |
1410 | |
1411 if (rc == NGX_DECLINED) { | |
573 | 1412 v->not_found = 1; |
1413 return NGX_OK; | |
539 | 1414 } |
1415 | |
1416 if (rc == NGX_ERROR) { | |
573 | 1417 return NGX_ERROR; |
539 | 1418 } |
1419 | |
573 | 1420 v->len = r->headers_in.user.len; |
1421 v->valid = 1; | |
1565 | 1422 v->no_cacheable = 0; |
573 | 1423 v->not_found = 0; |
1424 v->data = r->headers_in.user.data; | |
571 | 1425 |
573 | 1426 return NGX_OK; |
571 | 1427 } |
1428 | |
1429 | |
611 | 1430 static ngx_int_t |
1431 ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, | |
1432 ngx_http_variable_value_t *v, uintptr_t data) | |
1433 { | |
1434 off_t sent; | |
1435 u_char *p; | |
1436 | |
1437 sent = r->connection->sent - r->header_size; | |
1438 | |
1439 if (sent < 0) { | |
1440 sent = 0; | |
1441 } | |
1442 | |
2049 | 1443 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
611 | 1444 if (p == NULL) { |
1445 return NGX_ERROR; | |
1446 } | |
1447 | |
1448 v->len = ngx_sprintf(p, "%O", sent) - p; | |
1449 v->valid = 1; | |
1565 | 1450 v->no_cacheable = 0; |
611 | 1451 v->not_found = 0; |
1452 v->data = p; | |
1453 | |
1454 return NGX_OK; | |
1455 } | |
1456 | |
1457 | |
629 | 1458 static ngx_int_t |
641 | 1459 ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
1460 ngx_http_variable_value_t *v, uintptr_t data) | |
1461 { | |
1462 if (r->headers_out.content_type.len) { | |
1463 v->len = r->headers_out.content_type.len; | |
1464 v->valid = 1; | |
1565 | 1465 v->no_cacheable = 0; |
641 | 1466 v->not_found = 0; |
1467 v->data = r->headers_out.content_type.data; | |
1468 | |
1469 } else { | |
1470 v->not_found = 1; | |
1471 } | |
1472 | |
1473 return NGX_OK; | |
1474 } | |
1475 | |
1476 | |
1477 static ngx_int_t | |
1478 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
1479 ngx_http_variable_value_t *v, uintptr_t data) | |
1480 { | |
1481 u_char *p; | |
1482 | |
1483 if (r->headers_out.content_length) { | |
1484 v->len = r->headers_out.content_length->value.len; | |
1485 v->valid = 1; | |
1565 | 1486 v->no_cacheable = 0; |
641 | 1487 v->not_found = 0; |
1488 v->data = r->headers_out.content_length->value.data; | |
1489 | |
1490 return NGX_OK; | |
1491 } | |
1492 | |
1493 if (r->headers_out.content_length_n >= 0) { | |
2049 | 1494 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
641 | 1495 if (p == NULL) { |
1496 return NGX_ERROR; | |
1497 } | |
1498 | |
1499 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
1500 v->valid = 1; | |
1565 | 1501 v->no_cacheable = 0; |
641 | 1502 v->not_found = 0; |
1503 v->data = p; | |
1504 | |
1505 return NGX_OK; | |
1506 } | |
1507 | |
1508 v->not_found = 1; | |
1509 | |
1510 return NGX_OK; | |
1511 } | |
1512 | |
1513 | |
1514 static ngx_int_t | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1515 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
|
1516 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
|
1517 { |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1518 ngx_str_t name; |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1519 |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1520 if (r->headers_out.location) { |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1521 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
|
1522 v->valid = 1; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1523 v->no_cacheable = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1524 v->not_found = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1525 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
|
1526 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1527 return NGX_OK; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1528 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1529 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
1530 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
|
1531 |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1532 return ngx_http_variable_unknown_header(v, &name, |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1533 &r->headers_out.headers.part, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1534 sizeof("sent_http_") - 1); |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1535 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1536 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1537 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1538 static ngx_int_t |
641 | 1539 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
1540 ngx_http_variable_value_t *v, uintptr_t data) | |
1541 { | |
1542 u_char *p; | |
1543 | |
1544 if (r->headers_out.last_modified) { | |
1545 v->len = r->headers_out.last_modified->value.len; | |
1546 v->valid = 1; | |
1565 | 1547 v->no_cacheable = 0; |
641 | 1548 v->not_found = 0; |
1549 v->data = r->headers_out.last_modified->value.data; | |
1550 | |
1551 return NGX_OK; | |
1552 } | |
1553 | |
1554 if (r->headers_out.last_modified_time >= 0) { | |
2049 | 1555 p = ngx_pnalloc(r->pool, |
641 | 1556 sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
1557 if (p == NULL) { | |
1558 return NGX_ERROR; | |
1559 } | |
1560 | |
1561 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
1562 v->valid = 1; | |
1565 | 1563 v->no_cacheable = 0; |
641 | 1564 v->not_found = 0; |
1565 v->data = p; | |
1566 | |
1567 return NGX_OK; | |
1568 } | |
1569 | |
1570 v->not_found = 1; | |
1571 | |
1572 return NGX_OK; | |
1573 } | |
1574 | |
1575 | |
1576 static ngx_int_t | |
1577 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
1578 ngx_http_variable_value_t *v, uintptr_t data) | |
1579 { | |
1580 size_t len; | |
1581 char *p; | |
1582 | |
1583 if (r->keepalive) { | |
1584 len = sizeof("keep-alive") - 1; | |
1585 p = "keep-alive"; | |
1586 | |
1587 } else { | |
1588 len = sizeof("close") - 1; | |
1589 p = "close"; | |
1590 } | |
1591 | |
1592 v->len = len; | |
1593 v->valid = 1; | |
1565 | 1594 v->no_cacheable = 0; |
641 | 1595 v->not_found = 0; |
1596 v->data = (u_char *) p; | |
1597 | |
1598 return NGX_OK; | |
1599 } | |
1600 | |
1601 | |
1602 static ngx_int_t | |
1603 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
1604 ngx_http_variable_value_t *v, uintptr_t data) | |
1605 { | |
1606 u_char *p; | |
1607 ngx_http_core_loc_conf_t *clcf; | |
1608 | |
1609 if (r->keepalive) { | |
1610 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1611 | |
1612 if (clcf->keepalive_header) { | |
1613 | |
2049 | 1614 p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); |
641 | 1615 if (p == NULL) { |
1616 return NGX_ERROR; | |
1617 } | |
1618 | |
1619 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
1620 v->valid = 1; | |
1565 | 1621 v->no_cacheable = 0; |
641 | 1622 v->not_found = 0; |
1623 v->data = p; | |
1624 | |
1625 return NGX_OK; | |
1626 } | |
1627 } | |
1628 | |
1629 v->not_found = 1; | |
1630 | |
1631 return NGX_OK; | |
1632 } | |
1633 | |
1634 | |
1635 static ngx_int_t | |
1636 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
1637 ngx_http_variable_value_t *v, uintptr_t data) | |
1638 { | |
1639 if (r->chunked) { | |
1640 v->len = sizeof("chunked") - 1; | |
1641 v->valid = 1; | |
1565 | 1642 v->no_cacheable = 0; |
641 | 1643 v->not_found = 0; |
1644 v->data = (u_char *) "chunked"; | |
1645 | |
1646 } else { | |
1647 v->not_found = 1; | |
1648 } | |
1649 | |
1650 return NGX_OK; | |
1651 } | |
1652 | |
1653 | |
1654 static ngx_int_t | |
629 | 1655 ngx_http_variable_request_completion(ngx_http_request_t *r, |
1656 ngx_http_variable_value_t *v, uintptr_t data) | |
1657 { | |
1658 if (r->request_complete) { | |
1659 v->len = 2; | |
1660 v->valid = 1; | |
1565 | 1661 v->no_cacheable = 0; |
629 | 1662 v->not_found = 0; |
1663 v->data = (u_char *) "OK"; | |
1664 | |
1665 return NGX_OK; | |
1666 } | |
1667 | |
1668 v->len = 0; | |
1669 v->valid = 1; | |
1565 | 1670 v->no_cacheable = 0; |
629 | 1671 v->not_found = 0; |
1672 v->data = (u_char *) ""; | |
1673 | |
1674 return NGX_OK; | |
1675 } | |
1676 | |
1677 | |
759 | 1678 static ngx_int_t |
2844 | 1679 ngx_http_variable_request_body(ngx_http_request_t *r, |
1680 ngx_http_variable_value_t *v, uintptr_t data) | |
1681 { | |
1682 u_char *p; | |
1683 size_t len; | |
1684 ngx_buf_t *buf, *next; | |
1685 ngx_chain_t *cl; | |
1686 | |
2878
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1687 if (r->request_body == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1688 || r->request_body->bufs == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1689 || r->request_body->temp_file) |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1690 { |
2844 | 1691 v->not_found = 1; |
1692 | |
1693 return NGX_OK; | |
1694 } | |
1695 | |
1696 cl = r->request_body->bufs; | |
1697 buf = cl->buf; | |
1698 | |
1699 if (cl->next == NULL) { | |
1700 v->len = buf->last - buf->pos; | |
1701 v->valid = 1; | |
1702 v->no_cacheable = 0; | |
1703 v->not_found = 0; | |
1704 v->data = buf->pos; | |
1705 | |
1706 return NGX_OK; | |
1707 } | |
1708 | |
1709 next = cl->next->buf; | |
1710 len = (buf->last - buf->pos) + (next->last - next->pos); | |
1711 | |
1712 p = ngx_pnalloc(r->pool, len); | |
1713 if (p == NULL) { | |
1714 return NGX_ERROR; | |
1715 } | |
1716 | |
1717 v->data = p; | |
1718 | |
1719 p = ngx_cpymem(p, buf->pos, buf->last - buf->pos); | |
1720 ngx_memcpy(p, next->pos, next->last - next->pos); | |
1721 | |
1722 v->len = len; | |
1723 v->valid = 1; | |
1724 v->no_cacheable = 0; | |
1725 v->not_found = 0; | |
1726 | |
1727 return NGX_OK; | |
1728 } | |
1729 | |
1730 | |
1731 static ngx_int_t | |
759 | 1732 ngx_http_variable_request_body_file(ngx_http_request_t *r, |
1733 ngx_http_variable_value_t *v, uintptr_t data) | |
1734 { | |
1735 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
|
1736 v->not_found = 1; |
759 | 1737 |
1738 return NGX_OK; | |
1739 } | |
1740 | |
1741 v->len = r->request_body->temp_file->file.name.len; | |
1742 v->valid = 1; | |
1565 | 1743 v->no_cacheable = 0; |
759 | 1744 v->not_found = 0; |
1745 v->data = r->request_body->temp_file->file.name.data; | |
1746 | |
1747 return NGX_OK; | |
1748 } | |
1749 | |
1750 | |
1329 | 1751 static ngx_int_t |
1752 ngx_http_variable_nginx_version(ngx_http_request_t *r, | |
1753 ngx_http_variable_value_t *v, uintptr_t data) | |
1754 { | |
1755 v->len = sizeof(NGINX_VERSION) - 1; | |
1756 v->valid = 1; | |
1565 | 1757 v->no_cacheable = 0; |
1329 | 1758 v->not_found = 0; |
1759 v->data = (u_char *) NGINX_VERSION; | |
1760 | |
1761 return NGX_OK; | |
1762 } | |
1763 | |
1764 | |
2011 | 1765 static ngx_int_t |
1766 ngx_http_variable_hostname(ngx_http_request_t *r, | |
1767 ngx_http_variable_value_t *v, uintptr_t data) | |
1768 { | |
1769 v->len = ngx_cycle->hostname.len; | |
1770 v->valid = 1; | |
1771 v->no_cacheable = 0; | |
1772 v->not_found = 0; | |
1773 v->data = ngx_cycle->hostname.data; | |
1774 | |
1775 return NGX_OK; | |
1776 } | |
1777 | |
1778 | |
2249 | 1779 static ngx_int_t |
1780 ngx_http_variable_pid(ngx_http_request_t *r, | |
1781 ngx_http_variable_value_t *v, uintptr_t data) | |
1782 { | |
1783 u_char *p; | |
1784 | |
1785 p = ngx_pnalloc(r->pool, NGX_INT64_LEN); | |
1786 if (p == NULL) { | |
1787 return NGX_ERROR; | |
1788 } | |
1789 | |
1790 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; | |
1791 v->valid = 1; | |
1792 v->no_cacheable = 0; | |
1793 v->not_found = 0; | |
1794 v->data = p; | |
1795 | |
1796 return NGX_OK; | |
1797 } | |
1798 | |
1799 | |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1800 void * |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1801 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
|
1802 { |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1803 void *value; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1804 u_char *low; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1805 size_t len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1806 ngx_uint_t key; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1807 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1808 len = match->len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1809 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1810 if (len) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1811 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
|
1812 if (low == NULL) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1813 return NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1814 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1815 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1816 } else { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1817 low = NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1818 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1819 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1820 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
|
1821 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1822 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
|
1823 if (value) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
1824 return value; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1825 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1826 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1827 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1828 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1829 if (len && map->nregex) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1830 ngx_int_t n; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1831 ngx_uint_t i; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1832 ngx_http_map_regex_t *reg; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1833 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1834 reg = map->regex; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1835 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1836 for (i = 0; i < map->nregex; i++) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1837 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1838 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
|
1839 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1840 if (n == NGX_OK) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1841 return reg[i].value; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1842 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1843 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1844 if (n == NGX_DECLINED) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1845 continue; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1846 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1847 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1848 /* NGX_ERROR */ |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1849 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1850 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1851 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1852 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1853 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1854 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1855 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1856 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1857 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1858 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
1859 |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
1860 #if (NGX_PCRE) |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
1861 |
3325 | 1862 static ngx_int_t |
1863 ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
1864 uintptr_t data) | |
1865 { | |
1866 v->not_found = 1; | |
1867 return NGX_OK; | |
1868 } | |
1869 | |
1870 | |
1871 ngx_http_regex_t * | |
1872 ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
1873 { | |
1874 u_char *p; | |
1875 size_t size; | |
1876 ngx_str_t name; | |
1877 ngx_uint_t i, n; | |
1878 ngx_http_variable_t *v; | |
1879 ngx_http_regex_t *re; | |
1880 ngx_http_regex_variable_t *rv; | |
1881 ngx_http_core_main_conf_t *cmcf; | |
1882 | |
1883 rc->pool = cf->pool; | |
1884 | |
1885 if (ngx_regex_compile(rc) != NGX_OK) { | |
1886 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
1887 return NULL; | |
1888 } | |
1889 | |
1890 re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t)); | |
1891 if (re == NULL) { | |
1892 return NULL; | |
1893 } | |
1894 | |
1895 re->regex = rc->regex; | |
1896 re->ncaptures = rc->captures; | |
1897 | |
1898 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
1899 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
1900 | |
1901 n = (ngx_uint_t) rc->named_captures; | |
1902 | |
1903 if (n == 0) { | |
1904 return re; | |
1905 } | |
1906 | |
1907 rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t)); | |
1908 if (rv == NULL) { | |
1909 return NULL; | |
1910 } | |
1911 | |
1912 re->variables = rv; | |
1913 re->nvariables = n; | |
1914 re->name = rc->pattern; | |
1915 | |
1916 size = rc->name_size; | |
1917 p = rc->names; | |
1918 | |
1919 for (i = 0; i < n; i++) { | |
1920 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
1921 | |
1922 name.data = &p[2]; | |
1923 name.len = ngx_strlen(name.data); | |
1924 | |
1925 v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); | |
1926 if (v == NULL) { | |
1927 return NULL; | |
1928 } | |
1929 | |
1930 rv[i].index = ngx_http_get_variable_index(cf, &name); | |
1931 if (rv[i].index == NGX_ERROR) { | |
1932 return NULL; | |
1933 } | |
1934 | |
1935 v->get_handler = ngx_http_variable_not_found; | |
1936 | |
3409
bb79608169eb
named captures worked for two names only
Igor Sysoev <igor@sysoev.ru>
parents:
3356
diff
changeset
|
1937 p += size; |
3325 | 1938 } |
1939 | |
1940 return re; | |
1941 } | |
1942 | |
1943 | |
1944 ngx_int_t | |
1945 ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s) | |
1946 { | |
1947 ngx_int_t rc, index; | |
1948 ngx_uint_t i, n, len; | |
1949 ngx_http_variable_value_t *vv; | |
1950 ngx_http_core_main_conf_t *cmcf; | |
1951 | |
1952 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
1953 | |
1954 if (re->ncaptures) { | |
3345
d8228f0b5113
evaluate maximum captures size on configuration phase
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
1955 len = cmcf->ncaptures; |
3325 | 1956 |
1957 if (r->captures == NULL) { | |
1958 r->captures = ngx_palloc(r->pool, len * sizeof(int)); | |
1959 if (r->captures == NULL) { | |
1960 return NGX_ERROR; | |
1961 } | |
1962 } | |
1963 | |
1964 } else { | |
1965 len = 0; | |
1966 } | |
1967 | |
1968 rc = ngx_regex_exec(re->regex, s, r->captures, len); | |
1969 | |
1970 if (rc == NGX_REGEX_NO_MATCHED) { | |
1971 return NGX_DECLINED; | |
1972 } | |
1973 | |
1974 if (rc < 0) { | |
1975 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
1976 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
1977 rc, s, &re->name); | |
1978 return NGX_ERROR; | |
1979 } | |
1980 | |
1981 for (i = 0; i < re->nvariables; i++) { | |
1982 | |
1983 n = re->variables[i].capture; | |
1984 index = re->variables[i].index; | |
1985 vv = &r->variables[index]; | |
1986 | |
1987 vv->len = r->captures[n + 1] - r->captures[n]; | |
1988 vv->valid = 1; | |
1989 vv->no_cacheable = 0; | |
1990 vv->not_found = 0; | |
1991 vv->data = &s->data[r->captures[n]]; | |
1992 | |
1993 #if (NGX_DEBUG) | |
1994 { | |
1995 ngx_http_variable_t *v; | |
1996 | |
1997 v = cmcf->variables.elts; | |
1998 | |
1999 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2000 "http regex set $%V to \"%*s\"", | |
2001 &v[index].name, vv->len, vv->data); | |
2002 } | |
2003 #endif | |
2004 } | |
2005 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2006 r->ncaptures = rc * 2; |
3325 | 2007 r->captures_data = s->data; |
2008 | |
2009 return NGX_OK; | |
2010 } | |
2011 | |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2012 #endif |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2013 |
3325 | 2014 |
499 | 2015 ngx_int_t |
509 | 2016 ngx_http_variables_add_core_vars(ngx_conf_t *cf) |
499 | 2017 { |
611 | 2018 ngx_int_t rc; |
2019 ngx_http_variable_t *v; | |
501 | 2020 ngx_http_core_main_conf_t *cmcf; |
499 | 2021 |
509 | 2022 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2023 | |
611 | 2024 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, |
2025 sizeof(ngx_hash_keys_arrays_t)); | |
2026 if (cmcf->variables_keys == NULL) { | |
2027 return NGX_ERROR; | |
2028 } | |
2029 | |
2030 cmcf->variables_keys->pool = cf->pool; | |
2031 cmcf->variables_keys->temp_pool = cf->pool; | |
2032 | |
2033 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
2034 != NGX_OK) | |
509 | 2035 { |
499 | 2036 return NGX_ERROR; |
2037 } | |
2038 | |
611 | 2039 for (v = ngx_http_core_variables; v->name.len; v++) { |
2040 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, | |
2041 NGX_HASH_READONLY_KEY); | |
2042 | |
2043 if (rc == NGX_OK) { | |
2044 continue; | |
499 | 2045 } |
2046 | |
611 | 2047 if (rc == NGX_BUSY) { |
2048 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2049 "conflicting variable name \"%V\"", &v->name); | |
2050 } | |
2051 | |
2052 return NGX_ERROR; | |
499 | 2053 } |
2054 | |
2055 return NGX_OK; | |
2056 } | |
509 | 2057 |
2058 | |
2059 ngx_int_t | |
2060 ngx_http_variables_init_vars(ngx_conf_t *cf) | |
2061 { | |
2062 ngx_uint_t i, n; | |
611 | 2063 ngx_hash_key_t *key; |
2064 ngx_hash_init_t hash; | |
509 | 2065 ngx_http_variable_t *v, *av; |
2066 ngx_http_core_main_conf_t *cmcf; | |
2067 | |
2068 /* set the handlers for the indexed http variables */ | |
2069 | |
2070 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2071 | |
2072 v = cmcf->variables.elts; | |
611 | 2073 key = cmcf->variables_keys->keys.elts; |
509 | 2074 |
2075 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2076 | |
611 | 2077 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
509 | 2078 |
1191
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2079 av = key[n].value; |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2080 |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2081 if (av->get_handler |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2082 && v[i].name.len == key[n].key.len |
611 | 2083 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) |
509 | 2084 == 0) |
2085 { | |
637 | 2086 v[i].get_handler = av->get_handler; |
611 | 2087 v[i].data = av->data; |
527 | 2088 |
611 | 2089 av->flags |= NGX_HTTP_VAR_INDEXED; |
2090 v[i].flags = av->flags; | |
509 | 2091 |
611 | 2092 av->index = i; |
533 | 2093 |
509 | 2094 goto next; |
2095 } | |
2096 } | |
2097 | |
2098 if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) { | |
637 | 2099 v[i].get_handler = ngx_http_variable_unknown_header_in; |
577 | 2100 v[i].data = (uintptr_t) &v[i].name; |
2101 | |
2102 continue; | |
2103 } | |
2104 | |
2105 if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) { | |
637 | 2106 v[i].get_handler = ngx_http_variable_unknown_header_out; |
509 | 2107 v[i].data = (uintptr_t) &v[i].name; |
2108 | |
2109 continue; | |
2110 } | |
2111 | |
1162 | 2112 if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) { |
2113 v[i].get_handler = ngx_http_upstream_header_variable; | |
2114 v[i].data = (uintptr_t) &v[i].name; | |
1565 | 2115 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
1162 | 2116 |
2117 continue; | |
2118 } | |
2119 | |
2307 | 2120 if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) { |
2121 v[i].get_handler = ngx_http_variable_cookie; | |
2122 v[i].data = (uintptr_t) &v[i].name; | |
2123 | |
2124 continue; | |
2125 } | |
2126 | |
2137 | 2127 if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) { |
2128 v[i].get_handler = ngx_http_variable_argument; | |
2129 v[i].data = (uintptr_t) &v[i].name; | |
3499
b4a14d50388b
make $arg_ variables non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3463
diff
changeset
|
2130 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
2137 | 2131 |
2132 continue; | |
2133 } | |
2134 | |
509 | 2135 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
2136 "unknown \"%V\" variable", &v[i].name); | |
2137 | |
2138 return NGX_ERROR; | |
2139 | |
2140 next: | |
2141 continue; | |
2142 } | |
2143 | |
2144 | |
611 | 2145 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
2146 av = key[n].value; | |
2147 | |
2148 if (av->flags & NGX_HTTP_VAR_NOHASH) { | |
2149 key[n].key.data = NULL; | |
583 | 2150 } |
2151 } | |
2152 | |
2153 | |
611 | 2154 hash.hash = &cmcf->variables_hash; |
2155 hash.key = ngx_hash_key; | |
2156 hash.max_size = cmcf->variables_hash_max_size; | |
2157 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
2158 hash.name = "variables_hash"; | |
2159 hash.pool = cf->pool; | |
2160 hash.temp_pool = NULL; | |
509 | 2161 |
611 | 2162 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, |
2163 cmcf->variables_keys->keys.nelts) | |
581 | 2164 != NGX_OK) |
509 | 2165 { |
2166 return NGX_ERROR; | |
2167 } | |
2168 | |
611 | 2169 cmcf->variables_keys = NULL; |
509 | 2170 |
2171 return NGX_OK; | |
2172 } |