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