Mercurial > hg > nginx-quic
annotate src/http/ngx_http_variables.c @ 5405:620808518349
SPDY: ignore priority when queuing blocked frames.
With this change all such frames will be added in front of the output queue, and
will be sent first. It prevents HOL blocking when response with higher priority
is blocked by response with lower priority in the middle of the queue because
the order of their SYN_REPLY frames cannot be changed.
Proposed by Yury Kirpichev.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 01 Oct 2013 00:14:37 +0400 |
parents | 7094d6da2806 |
children | c21e341c51cb |
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, |
5327
6b479db5b52b
Format specifier fixes in error logging.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5316
diff
changeset
|
490 "unknown variable index: %ui", index); |
499 | 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 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1377 if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1378 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1379 { |
671 | 1380 return NGX_ERROR; |
1381 } | |
1382 | |
1383 v->len = path.len; | |
1384 v->valid = 1; | |
1565 | 1385 v->no_cacheable = 0; |
671 | 1386 v->not_found = 0; |
1387 v->data = path.data; | |
1388 } | |
509 | 1389 |
573 | 1390 return NGX_OK; |
509 | 1391 } |
1392 | |
1393 | |
573 | 1394 static ngx_int_t |
2259 | 1395 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1396 ngx_http_variable_value_t *v, uintptr_t data) | |
1397 { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1398 u_char *real; |
2259 | 1399 size_t len; |
1400 ngx_str_t path; | |
1401 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
|
1402 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1403 u_char buffer[NGX_MAX_PATH]; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1404 #endif |
2259 | 1405 |
1406 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1407 | |
1408 if (clcf->root_lengths == NULL) { | |
1409 path = clcf->root; | |
1410 | |
1411 } else { | |
1412 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1, | |
1413 clcf->root_values->elts) | |
1414 == NULL) | |
1415 { | |
1416 return NGX_ERROR; | |
1417 } | |
1418 | |
1419 path.data[path.len - 1] = '\0'; | |
1420 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1421 if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1422 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1423 { |
2259 | 1424 return NGX_ERROR; |
1425 } | |
1426 } | |
1427 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1428 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1429 real = buffer; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1430 #else |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1431 real = NULL; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1432 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1433 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1434 real = ngx_realpath(path.data, real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1435 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1436 if (real == NULL) { |
2259 | 1437 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1438 ngx_realpath_n " \"%s\" failed", path.data); | |
1439 return NGX_ERROR; | |
1440 } | |
1441 | |
1442 len = ngx_strlen(real); | |
1443 | |
1444 v->data = ngx_pnalloc(r->pool, len); | |
1445 if (v->data == NULL) { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1446 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1447 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1448 #endif |
2259 | 1449 return NGX_ERROR; |
1450 } | |
1451 | |
1452 v->len = len; | |
1453 v->valid = 1; | |
1454 v->no_cacheable = 0; | |
1455 v->not_found = 0; | |
1456 | |
1457 ngx_memcpy(v->data, real, len); | |
1458 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1459 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1460 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1461 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1462 |
2259 | 1463 return NGX_OK; |
1464 } | |
1465 | |
1466 | |
1467 static ngx_int_t | |
573 | 1468 ngx_http_variable_request_filename(ngx_http_request_t *r, |
1469 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1470 { |
773 | 1471 size_t root; |
573 | 1472 ngx_str_t path; |
499 | 1473 |
773 | 1474 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
573 | 1475 return NGX_ERROR; |
557 | 1476 } |
509 | 1477 |
557 | 1478 /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */ |
509 | 1479 |
573 | 1480 v->len = path.len - 1; |
1481 v->valid = 1; | |
1565 | 1482 v->no_cacheable = 0; |
573 | 1483 v->not_found = 0; |
1484 v->data = path.data; | |
499 | 1485 |
573 | 1486 return NGX_OK; |
499 | 1487 } |
1488 | |
1489 | |
573 | 1490 static ngx_int_t |
1811 | 1491 ngx_http_variable_server_name(ngx_http_request_t *r, |
1492 ngx_http_variable_value_t *v, uintptr_t data) | |
1493 { | |
1494 ngx_http_core_srv_conf_t *cscf; | |
1495 | |
1496 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1497 | |
1498 v->len = cscf->server_name.len; | |
1499 v->valid = 1; | |
1500 v->no_cacheable = 0; | |
1501 v->not_found = 0; | |
1502 v->data = cscf->server_name.data; | |
1503 | |
1504 return NGX_OK; | |
1505 } | |
1506 | |
1507 | |
1508 static ngx_int_t | |
573 | 1509 ngx_http_variable_request_method(ngx_http_request_t *r, |
1510 ngx_http_variable_value_t *v, uintptr_t data) | |
561 | 1511 { |
647 | 1512 if (r->main->method_name.data) { |
1513 v->len = r->main->method_name.len; | |
573 | 1514 v->valid = 1; |
1565 | 1515 v->no_cacheable = 0; |
573 | 1516 v->not_found = 0; |
647 | 1517 v->data = r->main->method_name.data; |
573 | 1518 |
1519 } else { | |
1520 v->not_found = 1; | |
561 | 1521 } |
1522 | |
573 | 1523 return NGX_OK; |
561 | 1524 } |
1525 | |
1526 | |
573 | 1527 static ngx_int_t |
1528 ngx_http_variable_remote_user(ngx_http_request_t *r, | |
1529 ngx_http_variable_value_t *v, uintptr_t data) | |
539 | 1530 { |
573 | 1531 ngx_int_t rc; |
539 | 1532 |
1533 rc = ngx_http_auth_basic_user(r); | |
1534 | |
1535 if (rc == NGX_DECLINED) { | |
573 | 1536 v->not_found = 1; |
1537 return NGX_OK; | |
539 | 1538 } |
1539 | |
1540 if (rc == NGX_ERROR) { | |
573 | 1541 return NGX_ERROR; |
539 | 1542 } |
1543 | |
573 | 1544 v->len = r->headers_in.user.len; |
1545 v->valid = 1; | |
1565 | 1546 v->no_cacheable = 0; |
573 | 1547 v->not_found = 0; |
1548 v->data = r->headers_in.user.data; | |
571 | 1549 |
573 | 1550 return NGX_OK; |
571 | 1551 } |
1552 | |
1553 | |
611 | 1554 static ngx_int_t |
4886 | 1555 ngx_http_variable_bytes_sent(ngx_http_request_t *r, |
1556 ngx_http_variable_value_t *v, uintptr_t data) | |
1557 { | |
1558 u_char *p; | |
1559 | |
1560 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); | |
1561 if (p == NULL) { | |
1562 return NGX_ERROR; | |
1563 } | |
1564 | |
1565 v->len = ngx_sprintf(p, "%O", r->connection->sent) - p; | |
1566 v->valid = 1; | |
1567 v->no_cacheable = 0; | |
1568 v->not_found = 0; | |
1569 v->data = p; | |
1570 | |
1571 return NGX_OK; | |
1572 } | |
1573 | |
1574 | |
1575 static ngx_int_t | |
611 | 1576 ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
1577 ngx_http_variable_value_t *v, uintptr_t data) | |
1578 { | |
1579 off_t sent; | |
1580 u_char *p; | |
1581 | |
1582 sent = r->connection->sent - r->header_size; | |
1583 | |
1584 if (sent < 0) { | |
1585 sent = 0; | |
1586 } | |
1587 | |
2049 | 1588 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
611 | 1589 if (p == NULL) { |
1590 return NGX_ERROR; | |
1591 } | |
1592 | |
1593 v->len = ngx_sprintf(p, "%O", sent) - p; | |
1594 v->valid = 1; | |
1565 | 1595 v->no_cacheable = 0; |
611 | 1596 v->not_found = 0; |
1597 v->data = p; | |
1598 | |
1599 return NGX_OK; | |
1600 } | |
1601 | |
1602 | |
629 | 1603 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1604 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
|
1605 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
|
1606 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1607 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
|
1608 v->len = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1609 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1610 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1611 v->not_found = 0; |
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 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1614 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1615 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1616 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1617 static ngx_int_t |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1618 ngx_http_variable_status(ngx_http_request_t *r, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1619 ngx_http_variable_value_t *v, uintptr_t data) |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1620 { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1621 ngx_uint_t status; |
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 v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1624 if (v->data == NULL) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1625 return NGX_ERROR; |
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 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1628 if (r->err_status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1629 status = r->err_status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1630 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1631 } else if (r->headers_out.status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1632 status = r->headers_out.status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1633 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1634 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1635 status = 9; |
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 } else { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1638 status = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1639 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1640 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1641 v->len = ngx_sprintf(v->data, "%03ui", status) - v->data; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1642 v->valid = 1; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1643 v->no_cacheable = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1644 v->not_found = 0; |
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 return NGX_OK; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1647 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1648 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1649 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1650 static ngx_int_t |
641 | 1651 ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
1652 ngx_http_variable_value_t *v, uintptr_t data) | |
1653 { | |
1654 if (r->headers_out.content_type.len) { | |
1655 v->len = r->headers_out.content_type.len; | |
1656 v->valid = 1; | |
1565 | 1657 v->no_cacheable = 0; |
641 | 1658 v->not_found = 0; |
1659 v->data = r->headers_out.content_type.data; | |
1660 | |
1661 } else { | |
1662 v->not_found = 1; | |
1663 } | |
1664 | |
1665 return NGX_OK; | |
1666 } | |
1667 | |
1668 | |
1669 static ngx_int_t | |
1670 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
1671 ngx_http_variable_value_t *v, uintptr_t data) | |
1672 { | |
1673 u_char *p; | |
1674 | |
1675 if (r->headers_out.content_length) { | |
1676 v->len = r->headers_out.content_length->value.len; | |
1677 v->valid = 1; | |
1565 | 1678 v->no_cacheable = 0; |
641 | 1679 v->not_found = 0; |
1680 v->data = r->headers_out.content_length->value.data; | |
1681 | |
1682 return NGX_OK; | |
1683 } | |
1684 | |
1685 if (r->headers_out.content_length_n >= 0) { | |
2049 | 1686 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
641 | 1687 if (p == NULL) { |
1688 return NGX_ERROR; | |
1689 } | |
1690 | |
1691 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
1692 v->valid = 1; | |
1565 | 1693 v->no_cacheable = 0; |
641 | 1694 v->not_found = 0; |
1695 v->data = p; | |
1696 | |
1697 return NGX_OK; | |
1698 } | |
1699 | |
1700 v->not_found = 1; | |
1701 | |
1702 return NGX_OK; | |
1703 } | |
1704 | |
1705 | |
1706 static ngx_int_t | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1707 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
|
1708 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
|
1709 { |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1710 ngx_str_t name; |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1711 |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1712 if (r->headers_out.location) { |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1713 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
|
1714 v->valid = 1; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1715 v->no_cacheable = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1716 v->not_found = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1717 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
|
1718 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1719 return NGX_OK; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1720 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1721 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
1722 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
|
1723 |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1724 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
|
1725 &r->headers_out.headers.part, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1726 sizeof("sent_http_") - 1); |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1727 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1728 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1729 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1730 static ngx_int_t |
641 | 1731 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
1732 ngx_http_variable_value_t *v, uintptr_t data) | |
1733 { | |
1734 u_char *p; | |
1735 | |
1736 if (r->headers_out.last_modified) { | |
1737 v->len = r->headers_out.last_modified->value.len; | |
1738 v->valid = 1; | |
1565 | 1739 v->no_cacheable = 0; |
641 | 1740 v->not_found = 0; |
1741 v->data = r->headers_out.last_modified->value.data; | |
1742 | |
1743 return NGX_OK; | |
1744 } | |
1745 | |
1746 if (r->headers_out.last_modified_time >= 0) { | |
2049 | 1747 p = ngx_pnalloc(r->pool, |
641 | 1748 sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
1749 if (p == NULL) { | |
1750 return NGX_ERROR; | |
1751 } | |
1752 | |
1753 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
1754 v->valid = 1; | |
1565 | 1755 v->no_cacheable = 0; |
641 | 1756 v->not_found = 0; |
1757 v->data = p; | |
1758 | |
1759 return NGX_OK; | |
1760 } | |
1761 | |
1762 v->not_found = 1; | |
1763 | |
1764 return NGX_OK; | |
1765 } | |
1766 | |
1767 | |
1768 static ngx_int_t | |
1769 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
1770 ngx_http_variable_value_t *v, uintptr_t data) | |
1771 { | |
1772 size_t len; | |
1773 char *p; | |
1774 | |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1775 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
|
1776 len = sizeof("upgrade") - 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1777 p = "upgrade"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1778 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1779 } else if (r->keepalive) { |
641 | 1780 len = sizeof("keep-alive") - 1; |
1781 p = "keep-alive"; | |
1782 | |
1783 } else { | |
1784 len = sizeof("close") - 1; | |
1785 p = "close"; | |
1786 } | |
1787 | |
1788 v->len = len; | |
1789 v->valid = 1; | |
1565 | 1790 v->no_cacheable = 0; |
641 | 1791 v->not_found = 0; |
1792 v->data = (u_char *) p; | |
1793 | |
1794 return NGX_OK; | |
1795 } | |
1796 | |
1797 | |
1798 static ngx_int_t | |
1799 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
1800 ngx_http_variable_value_t *v, uintptr_t data) | |
1801 { | |
1802 u_char *p; | |
1803 ngx_http_core_loc_conf_t *clcf; | |
1804 | |
1805 if (r->keepalive) { | |
1806 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1807 | |
1808 if (clcf->keepalive_header) { | |
1809 | |
2049 | 1810 p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); |
641 | 1811 if (p == NULL) { |
1812 return NGX_ERROR; | |
1813 } | |
1814 | |
1815 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
1816 v->valid = 1; | |
1565 | 1817 v->no_cacheable = 0; |
641 | 1818 v->not_found = 0; |
1819 v->data = p; | |
1820 | |
1821 return NGX_OK; | |
1822 } | |
1823 } | |
1824 | |
1825 v->not_found = 1; | |
1826 | |
1827 return NGX_OK; | |
1828 } | |
1829 | |
1830 | |
1831 static ngx_int_t | |
1832 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
1833 ngx_http_variable_value_t *v, uintptr_t data) | |
1834 { | |
1835 if (r->chunked) { | |
1836 v->len = sizeof("chunked") - 1; | |
1837 v->valid = 1; | |
1565 | 1838 v->no_cacheable = 0; |
641 | 1839 v->not_found = 0; |
1840 v->data = (u_char *) "chunked"; | |
1841 | |
1842 } else { | |
1843 v->not_found = 1; | |
1844 } | |
1845 | |
1846 return NGX_OK; | |
1847 } | |
1848 | |
1849 | |
1850 static ngx_int_t | |
629 | 1851 ngx_http_variable_request_completion(ngx_http_request_t *r, |
1852 ngx_http_variable_value_t *v, uintptr_t data) | |
1853 { | |
1854 if (r->request_complete) { | |
1855 v->len = 2; | |
1856 v->valid = 1; | |
1565 | 1857 v->no_cacheable = 0; |
629 | 1858 v->not_found = 0; |
1859 v->data = (u_char *) "OK"; | |
1860 | |
1861 return NGX_OK; | |
1862 } | |
1863 | |
1864 v->len = 0; | |
1865 v->valid = 1; | |
1565 | 1866 v->no_cacheable = 0; |
629 | 1867 v->not_found = 0; |
1868 v->data = (u_char *) ""; | |
1869 | |
1870 return NGX_OK; | |
1871 } | |
1872 | |
1873 | |
759 | 1874 static ngx_int_t |
2844 | 1875 ngx_http_variable_request_body(ngx_http_request_t *r, |
1876 ngx_http_variable_value_t *v, uintptr_t data) | |
1877 { | |
1878 u_char *p; | |
1879 size_t len; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1880 ngx_buf_t *buf; |
2844 | 1881 ngx_chain_t *cl; |
1882 | |
2878
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1883 if (r->request_body == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1884 || r->request_body->bufs == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1885 || r->request_body->temp_file) |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1886 { |
2844 | 1887 v->not_found = 1; |
1888 | |
1889 return NGX_OK; | |
1890 } | |
1891 | |
1892 cl = r->request_body->bufs; | |
1893 buf = cl->buf; | |
1894 | |
1895 if (cl->next == NULL) { | |
1896 v->len = buf->last - buf->pos; | |
1897 v->valid = 1; | |
1898 v->no_cacheable = 0; | |
1899 v->not_found = 0; | |
1900 v->data = buf->pos; | |
1901 | |
1902 return NGX_OK; | |
1903 } | |
1904 | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1905 len = buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1906 cl = cl->next; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1907 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1908 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1909 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1910 len += buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1911 } |
2844 | 1912 |
1913 p = ngx_pnalloc(r->pool, len); | |
1914 if (p == NULL) { | |
1915 return NGX_ERROR; | |
1916 } | |
1917 | |
1918 v->data = p; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1919 cl = r->request_body->bufs; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1920 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1921 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1922 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1923 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
|
1924 } |
2844 | 1925 |
1926 v->len = len; | |
1927 v->valid = 1; | |
1928 v->no_cacheable = 0; | |
1929 v->not_found = 0; | |
1930 | |
1931 return NGX_OK; | |
1932 } | |
1933 | |
1934 | |
1935 static ngx_int_t | |
759 | 1936 ngx_http_variable_request_body_file(ngx_http_request_t *r, |
1937 ngx_http_variable_value_t *v, uintptr_t data) | |
1938 { | |
1939 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
|
1940 v->not_found = 1; |
759 | 1941 |
1942 return NGX_OK; | |
1943 } | |
1944 | |
1945 v->len = r->request_body->temp_file->file.name.len; | |
1946 v->valid = 1; | |
1565 | 1947 v->no_cacheable = 0; |
759 | 1948 v->not_found = 0; |
1949 v->data = r->request_body->temp_file->file.name.data; | |
1950 | |
1951 return NGX_OK; | |
1952 } | |
1953 | |
1954 | |
1329 | 1955 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1956 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
|
1957 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
|
1958 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1959 u_char *p; |
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 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
|
1962 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1963 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1964 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1965 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1966 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
|
1967 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1968 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1969 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1970 v->data = p; |
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 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1973 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1974 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1975 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1976 static ngx_int_t |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1977 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
|
1978 ngx_http_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1981 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1982 ngx_msec_int_t ms; |
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 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
|
1985 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1986 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1987 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1988 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1989 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1990 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1991 ms = (ngx_msec_int_t) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1992 ((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
|
1993 ms = ngx_max(ms, 0); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1994 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5327
diff
changeset
|
1995 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
|
1996 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1997 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1998 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1999 v->data = p; |
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 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2002 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2003 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2004 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2005 static ngx_int_t |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2006 ngx_http_variable_connection(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2007 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2008 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2009 u_char *p; |
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 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2012 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2013 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2014 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2015 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2016 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
|
2017 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2018 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2019 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2020 v->data = p; |
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 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2023 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2024 |
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 static ngx_int_t |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2027 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
|
2028 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2029 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2030 u_char *p; |
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 p = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2033 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2034 return NGX_ERROR; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2035 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2036 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2037 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
|
2038 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2039 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2040 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2041 v->data = p; |
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 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2044 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2045 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2046 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2047 static ngx_int_t |
1329 | 2048 ngx_http_variable_nginx_version(ngx_http_request_t *r, |
2049 ngx_http_variable_value_t *v, uintptr_t data) | |
2050 { | |
2051 v->len = sizeof(NGINX_VERSION) - 1; | |
2052 v->valid = 1; | |
1565 | 2053 v->no_cacheable = 0; |
1329 | 2054 v->not_found = 0; |
2055 v->data = (u_char *) NGINX_VERSION; | |
2056 | |
2057 return NGX_OK; | |
2058 } | |
2059 | |
2060 | |
2011 | 2061 static ngx_int_t |
2062 ngx_http_variable_hostname(ngx_http_request_t *r, | |
2063 ngx_http_variable_value_t *v, uintptr_t data) | |
2064 { | |
2065 v->len = ngx_cycle->hostname.len; | |
2066 v->valid = 1; | |
2067 v->no_cacheable = 0; | |
2068 v->not_found = 0; | |
2069 v->data = ngx_cycle->hostname.data; | |
2070 | |
2071 return NGX_OK; | |
2072 } | |
2073 | |
2074 | |
2249 | 2075 static ngx_int_t |
2076 ngx_http_variable_pid(ngx_http_request_t *r, | |
2077 ngx_http_variable_value_t *v, uintptr_t data) | |
2078 { | |
2079 u_char *p; | |
2080 | |
2081 p = ngx_pnalloc(r->pool, NGX_INT64_LEN); | |
2082 if (p == NULL) { | |
2083 return NGX_ERROR; | |
2084 } | |
2085 | |
2086 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; | |
2087 v->valid = 1; | |
2088 v->no_cacheable = 0; | |
2089 v->not_found = 0; | |
2090 v->data = p; | |
2091 | |
2092 return NGX_OK; | |
2093 } | |
2094 | |
2095 | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2096 static ngx_int_t |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2097 ngx_http_variable_msec(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2098 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2099 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2100 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2101 ngx_time_t *tp; |
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 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
|
2104 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2105 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2106 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2107 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2108 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2109 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2110 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
|
2111 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2112 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2113 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2114 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2115 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2116 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2117 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2118 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2119 |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2120 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2121 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
|
2122 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
|
2123 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2124 u_char *p; |
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 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
|
2127 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2128 return NGX_ERROR; |
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 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2131 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
|
2132 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
|
2133 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2134 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
|
2135 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2136 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2137 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2138 v->data = p; |
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 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2141 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2142 |
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 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2145 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
|
2146 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
|
2147 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2148 u_char *p; |
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 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
|
2151 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2152 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2153 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2154 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2155 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
|
2156 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2157 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
|
2158 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2159 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2160 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2161 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2162 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2163 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2164 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2165 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2166 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2167 void * |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2168 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
|
2169 { |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2170 void *value; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2171 u_char *low; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2172 size_t len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2173 ngx_uint_t key; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2174 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2175 len = match->len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2176 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2177 if (len) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2178 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
|
2179 if (low == NULL) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2180 return 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 } else { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2184 low = NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2185 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2186 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2187 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
|
2188 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2189 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
|
2190 if (value) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2191 return value; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2192 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2193 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2194 #if (NGX_PCRE) |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2195 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2196 if (len && map->nregex) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2197 ngx_int_t n; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2198 ngx_uint_t i; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2199 ngx_http_map_regex_t *reg; |
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 reg = map->regex; |
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 for (i = 0; i < map->nregex; i++) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2204 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2205 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
|
2206 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2207 if (n == NGX_OK) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2208 return reg[i].value; |
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 if (n == NGX_DECLINED) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2212 continue; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2213 } |
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 /* NGX_ERROR */ |
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 return NULL; |
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 } |
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 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2222 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2223 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2224 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2225 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2226 |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2227 #if (NGX_PCRE) |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2228 |
3325 | 2229 static ngx_int_t |
2230 ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
2231 uintptr_t data) | |
2232 { | |
2233 v->not_found = 1; | |
2234 return NGX_OK; | |
2235 } | |
2236 | |
2237 | |
2238 ngx_http_regex_t * | |
2239 ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
2240 { | |
2241 u_char *p; | |
2242 size_t size; | |
2243 ngx_str_t name; | |
2244 ngx_uint_t i, n; | |
2245 ngx_http_variable_t *v; | |
2246 ngx_http_regex_t *re; | |
2247 ngx_http_regex_variable_t *rv; | |
2248 ngx_http_core_main_conf_t *cmcf; | |
2249 | |
2250 rc->pool = cf->pool; | |
2251 | |
2252 if (ngx_regex_compile(rc) != NGX_OK) { | |
2253 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
2254 return NULL; | |
2255 } | |
2256 | |
2257 re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t)); | |
2258 if (re == NULL) { | |
2259 return NULL; | |
2260 } | |
2261 | |
2262 re->regex = rc->regex; | |
2263 re->ncaptures = rc->captures; | |
5204
a64c8a5da336
PCRE: retain input pattern for all regular expressions.
Piotr Sikora <piotr@cloudflare.com>
parents:
5084
diff
changeset
|
2264 re->name = rc->pattern; |
3325 | 2265 |
2266 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2267 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
2268 | |
2269 n = (ngx_uint_t) rc->named_captures; | |
2270 | |
2271 if (n == 0) { | |
2272 return re; | |
2273 } | |
2274 | |
2275 rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t)); | |
2276 if (rv == NULL) { | |
2277 return NULL; | |
2278 } | |
2279 | |
2280 re->variables = rv; | |
2281 re->nvariables = n; | |
2282 | |
2283 size = rc->name_size; | |
2284 p = rc->names; | |
2285 | |
2286 for (i = 0; i < n; i++) { | |
2287 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
2288 | |
2289 name.data = &p[2]; | |
2290 name.len = ngx_strlen(name.data); | |
2291 | |
2292 v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); | |
2293 if (v == NULL) { | |
2294 return NULL; | |
2295 } | |
2296 | |
2297 rv[i].index = ngx_http_get_variable_index(cf, &name); | |
2298 if (rv[i].index == NGX_ERROR) { | |
2299 return NULL; | |
2300 } | |
2301 | |
2302 v->get_handler = ngx_http_variable_not_found; | |
2303 | |
3409
bb79608169eb
named captures worked for two names only
Igor Sysoev <igor@sysoev.ru>
parents:
3356
diff
changeset
|
2304 p += size; |
3325 | 2305 } |
2306 | |
2307 return re; | |
2308 } | |
2309 | |
2310 | |
2311 ngx_int_t | |
2312 ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s) | |
2313 { | |
2314 ngx_int_t rc, index; | |
2315 ngx_uint_t i, n, len; | |
2316 ngx_http_variable_value_t *vv; | |
2317 ngx_http_core_main_conf_t *cmcf; | |
2318 | |
2319 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
2320 | |
2321 if (re->ncaptures) { | |
3345
d8228f0b5113
evaluate maximum captures size on configuration phase
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
2322 len = cmcf->ncaptures; |
3325 | 2323 |
2324 if (r->captures == NULL) { | |
2325 r->captures = ngx_palloc(r->pool, len * sizeof(int)); | |
2326 if (r->captures == NULL) { | |
2327 return NGX_ERROR; | |
2328 } | |
2329 } | |
2330 | |
2331 } else { | |
2332 len = 0; | |
2333 } | |
2334 | |
2335 rc = ngx_regex_exec(re->regex, s, r->captures, len); | |
2336 | |
2337 if (rc == NGX_REGEX_NO_MATCHED) { | |
2338 return NGX_DECLINED; | |
2339 } | |
2340 | |
2341 if (rc < 0) { | |
2342 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
2343 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
2344 rc, s, &re->name); | |
2345 return NGX_ERROR; | |
2346 } | |
2347 | |
2348 for (i = 0; i < re->nvariables; i++) { | |
2349 | |
2350 n = re->variables[i].capture; | |
2351 index = re->variables[i].index; | |
2352 vv = &r->variables[index]; | |
2353 | |
2354 vv->len = r->captures[n + 1] - r->captures[n]; | |
2355 vv->valid = 1; | |
2356 vv->no_cacheable = 0; | |
2357 vv->not_found = 0; | |
2358 vv->data = &s->data[r->captures[n]]; | |
2359 | |
2360 #if (NGX_DEBUG) | |
2361 { | |
2362 ngx_http_variable_t *v; | |
2363 | |
2364 v = cmcf->variables.elts; | |
2365 | |
2366 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2367 "http regex set $%V to \"%*s\"", | |
2368 &v[index].name, vv->len, vv->data); | |
2369 } | |
2370 #endif | |
2371 } | |
2372 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2373 r->ncaptures = rc * 2; |
3325 | 2374 r->captures_data = s->data; |
2375 | |
2376 return NGX_OK; | |
2377 } | |
2378 | |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2379 #endif |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2380 |
3325 | 2381 |
499 | 2382 ngx_int_t |
509 | 2383 ngx_http_variables_add_core_vars(ngx_conf_t *cf) |
499 | 2384 { |
611 | 2385 ngx_int_t rc; |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2386 ngx_http_variable_t *cv, *v; |
501 | 2387 ngx_http_core_main_conf_t *cmcf; |
499 | 2388 |
509 | 2389 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2390 | |
611 | 2391 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, |
2392 sizeof(ngx_hash_keys_arrays_t)); | |
2393 if (cmcf->variables_keys == NULL) { | |
2394 return NGX_ERROR; | |
2395 } | |
2396 | |
2397 cmcf->variables_keys->pool = cf->pool; | |
2398 cmcf->variables_keys->temp_pool = cf->pool; | |
2399 | |
2400 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
2401 != NGX_OK) | |
509 | 2402 { |
499 | 2403 return NGX_ERROR; |
2404 } | |
2405 | |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2406 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
|
2407 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
|
2408 if (v == NULL) { |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2409 return NGX_ERROR; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2410 } |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2411 |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2412 *v = *cv; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2413 |
611 | 2414 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, |
2415 NGX_HASH_READONLY_KEY); | |
2416 | |
2417 if (rc == NGX_OK) { | |
2418 continue; | |
499 | 2419 } |
2420 | |
611 | 2421 if (rc == NGX_BUSY) { |
2422 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2423 "conflicting variable name \"%V\"", &v->name); | |
2424 } | |
2425 | |
2426 return NGX_ERROR; | |
499 | 2427 } |
2428 | |
2429 return NGX_OK; | |
2430 } | |
509 | 2431 |
2432 | |
2433 ngx_int_t | |
2434 ngx_http_variables_init_vars(ngx_conf_t *cf) | |
2435 { | |
2436 ngx_uint_t i, n; | |
611 | 2437 ngx_hash_key_t *key; |
2438 ngx_hash_init_t hash; | |
509 | 2439 ngx_http_variable_t *v, *av; |
2440 ngx_http_core_main_conf_t *cmcf; | |
2441 | |
2442 /* set the handlers for the indexed http variables */ | |
2443 | |
2444 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2445 | |
2446 v = cmcf->variables.elts; | |
611 | 2447 key = cmcf->variables_keys->keys.elts; |
509 | 2448 |
2449 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2450 | |
611 | 2451 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
509 | 2452 |
1191
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2453 av = key[n].value; |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2454 |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2455 if (av->get_handler |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2456 && v[i].name.len == key[n].key.len |
611 | 2457 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) |
509 | 2458 == 0) |
2459 { | |
637 | 2460 v[i].get_handler = av->get_handler; |
611 | 2461 v[i].data = av->data; |
527 | 2462 |
611 | 2463 av->flags |= NGX_HTTP_VAR_INDEXED; |
2464 v[i].flags = av->flags; | |
509 | 2465 |
611 | 2466 av->index = i; |
533 | 2467 |
509 | 2468 goto next; |
2469 } | |
2470 } | |
2471 | |
2472 if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) { | |
637 | 2473 v[i].get_handler = ngx_http_variable_unknown_header_in; |
577 | 2474 v[i].data = (uintptr_t) &v[i].name; |
2475 | |
2476 continue; | |
2477 } | |
2478 | |
2479 if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) { | |
637 | 2480 v[i].get_handler = ngx_http_variable_unknown_header_out; |
509 | 2481 v[i].data = (uintptr_t) &v[i].name; |
2482 | |
2483 continue; | |
2484 } | |
2485 | |
1162 | 2486 if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) { |
2487 v[i].get_handler = ngx_http_upstream_header_variable; | |
2488 v[i].data = (uintptr_t) &v[i].name; | |
1565 | 2489 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
1162 | 2490 |
2491 continue; | |
2492 } | |
2493 | |
2307 | 2494 if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) { |
2495 v[i].get_handler = ngx_http_variable_cookie; | |
2496 v[i].data = (uintptr_t) &v[i].name; | |
2497 | |
2498 continue; | |
2499 } | |
2500 | |
2137 | 2501 if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) { |
2502 v[i].get_handler = ngx_http_variable_argument; | |
2503 v[i].data = (uintptr_t) &v[i].name; | |
3499
b4a14d50388b
make $arg_ variables non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3463
diff
changeset
|
2504 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
2137 | 2505 |
2506 continue; | |
2507 } | |
2508 | |
509 | 2509 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
2510 "unknown \"%V\" variable", &v[i].name); | |
2511 | |
2512 return NGX_ERROR; | |
2513 | |
2514 next: | |
2515 continue; | |
2516 } | |
2517 | |
2518 | |
611 | 2519 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
2520 av = key[n].value; | |
2521 | |
2522 if (av->flags & NGX_HTTP_VAR_NOHASH) { | |
2523 key[n].key.data = NULL; | |
583 | 2524 } |
2525 } | |
2526 | |
2527 | |
611 | 2528 hash.hash = &cmcf->variables_hash; |
2529 hash.key = ngx_hash_key; | |
2530 hash.max_size = cmcf->variables_hash_max_size; | |
2531 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
2532 hash.name = "variables_hash"; | |
2533 hash.pool = cf->pool; | |
2534 hash.temp_pool = NULL; | |
509 | 2535 |
611 | 2536 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, |
2537 cmcf->variables_keys->keys.nelts) | |
581 | 2538 != NGX_OK) |
509 | 2539 { |
2540 return NGX_ERROR; | |
2541 } | |
2542 | |
611 | 2543 cmcf->variables_keys = NULL; |
509 | 2544 |
2545 return NGX_OK; | |
2546 } |