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