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