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