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