Mercurial > hg > nginx-quic
annotate src/http/ngx_http_variables.c @ 5465:a279d2a33dbf
SPDY: drop the "delayed" flag when finalizing connection.
This flag in SPDY fake write events serves the same purposes as the "ready"
flag in real events, and it must be dropped if request needs to be handled.
Otherwise, it can prevent the request from finalization if ngx_http_writer()
was set, which results in a connection leak.
Found by Xiaochen Wang.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Tue, 10 Dec 2013 20:27:33 +0400 |
parents | 30e806b8636a |
children | 3a72b1805c52 |
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 |
5464
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1188 #if (NGX_HAVE_UNIX_DOMAIN) |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1189 case AF_UNIX: |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1190 port = 0; |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1191 break; |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1192 #endif |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1193 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1194 default: /* AF_INET */ |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1195 sin = (struct sockaddr_in *) r->connection->sockaddr; |
509 | 1196 port = ntohs(sin->sin_port); |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1197 break; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1198 } |
577 | 1199 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1200 if (port > 0 && port < 65536) { |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1201 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; |
509 | 1202 } |
1203 | |
573 | 1204 return NGX_OK; |
509 | 1205 } |
1206 | |
1207 | |
573 | 1208 static ngx_int_t |
1209 ngx_http_variable_server_addr(ngx_http_request_t *r, | |
1210 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1211 { |
1805 | 1212 ngx_str_t s; |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1213 u_char addr[NGX_SOCKADDR_STRLEN]; |
499 | 1214 |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1215 s.len = NGX_SOCKADDR_STRLEN; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1216 s.data = addr; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1217 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1218 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
|
1219 return NGX_ERROR; |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1220 } |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1221 |
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1222 s.data = ngx_pnalloc(r->pool, s.len); |
1805 | 1223 if (s.data == NULL) { |
573 | 1224 return NGX_ERROR; |
509 | 1225 } |
1226 | |
2512
2e91aecb9e57
a prelimiary IPv6 support, HTTP listen
Igor Sysoev <igor@sysoev.ru>
parents:
2485
diff
changeset
|
1227 ngx_memcpy(s.data, addr, s.len); |
509 | 1228 |
1805 | 1229 v->len = s.len; |
573 | 1230 v->valid = 1; |
1565 | 1231 v->no_cacheable = 0; |
573 | 1232 v->not_found = 0; |
1805 | 1233 v->data = s.data; |
499 | 1234 |
573 | 1235 return NGX_OK; |
499 | 1236 } |
1237 | |
1238 | |
573 | 1239 static ngx_int_t |
1240 ngx_http_variable_server_port(ngx_http_request_t *r, | |
1241 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1242 { |
2533 | 1243 ngx_uint_t port; |
1244 struct sockaddr_in *sin; | |
1245 #if (NGX_HAVE_INET6) | |
1246 struct sockaddr_in6 *sin6; | |
1247 #endif | |
1248 | |
1249 v->len = 0; | |
573 | 1250 v->valid = 1; |
1565 | 1251 v->no_cacheable = 0; |
573 | 1252 v->not_found = 0; |
2533 | 1253 |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2844
diff
changeset
|
1254 if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) { |
2533 | 1255 return NGX_ERROR; |
1256 } | |
1257 | |
1258 v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1); | |
1259 if (v->data == NULL) { | |
1260 return NGX_ERROR; | |
1261 } | |
1262 | |
1263 switch (r->connection->local_sockaddr->sa_family) { | |
1264 | |
1265 #if (NGX_HAVE_INET6) | |
1266 case AF_INET6: | |
1267 sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr; | |
1268 port = ntohs(sin6->sin6_port); | |
1269 break; | |
1270 #endif | |
1271 | |
5464
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1272 #if (NGX_HAVE_UNIX_DOMAIN) |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1273 case AF_UNIX: |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1274 port = 0; |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1275 break; |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1276 #endif |
30e806b8636a
Fixed handling of UNIX-domain sockets.
Ruslan Ermilov <ru@nginx.com>
parents:
5434
diff
changeset
|
1277 |
2533 | 1278 default: /* AF_INET */ |
1279 sin = (struct sockaddr_in *) r->connection->local_sockaddr; | |
1280 port = ntohs(sin->sin_port); | |
1281 break; | |
1282 } | |
1283 | |
1284 if (port > 0 && port < 65536) { | |
1285 v->len = ngx_sprintf(v->data, "%ui", port) - v->data; | |
1286 } | |
509 | 1287 |
573 | 1288 return NGX_OK; |
509 | 1289 } |
1290 | |
1291 | |
573 | 1292 static ngx_int_t |
731 | 1293 ngx_http_variable_scheme(ngx_http_request_t *r, |
1294 ngx_http_variable_value_t *v, uintptr_t data) | |
1295 { | |
1296 #if (NGX_HTTP_SSL) | |
1297 | |
1298 if (r->connection->ssl) { | |
1299 v->len = sizeof("https") - 1; | |
1300 v->valid = 1; | |
1565 | 1301 v->no_cacheable = 0; |
731 | 1302 v->not_found = 0; |
732 | 1303 v->data = (u_char *) "https"; |
731 | 1304 |
1305 return NGX_OK; | |
1306 } | |
1307 | |
1308 #endif | |
1309 | |
1310 v->len = sizeof("http") - 1; | |
1311 v->valid = 1; | |
1565 | 1312 v->no_cacheable = 0; |
731 | 1313 v->not_found = 0; |
732 | 1314 v->data = (u_char *) "http"; |
731 | 1315 |
1316 return NGX_OK; | |
1317 } | |
1318 | |
1319 | |
1320 static ngx_int_t | |
4332
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1321 ngx_http_variable_https(ngx_http_request_t *r, |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1322 ngx_http_variable_value_t *v, uintptr_t data) |
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 #if (NGX_HTTP_SSL) |
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 if (r->connection->ssl) { |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1327 v->len = sizeof("on") - 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1328 v->valid = 1; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1329 v->no_cacheable = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1330 v->not_found = 0; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1331 v->data = (u_char *) "on"; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1332 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1333 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1334 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1335 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1336 #endif |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1337 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1338 *v = ngx_http_variable_null_value; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1339 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1340 return NGX_OK; |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1341 } |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1342 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1343 |
4d9f985fd217
Added the $https variable.
Valentin Bartenev <vbart@nginx.com>
parents:
3929
diff
changeset
|
1344 static ngx_int_t |
1351 | 1345 ngx_http_variable_is_args(ngx_http_request_t *r, |
1346 ngx_http_variable_value_t *v, uintptr_t data) | |
1347 { | |
1348 v->valid = 1; | |
1565 | 1349 v->no_cacheable = 0; |
1351 | 1350 v->not_found = 0; |
1351 | |
1352 if (r->args.len == 0) { | |
1353 v->len = 0; | |
1354 v->data = NULL; | |
1355 return NGX_OK; | |
1356 } | |
1357 | |
1358 v->len = 1; | |
1359 v->data = (u_char *) "?"; | |
1360 | |
1361 return NGX_OK; | |
1362 } | |
1363 | |
1364 | |
1365 static ngx_int_t | |
573 | 1366 ngx_http_variable_document_root(ngx_http_request_t *r, |
1367 ngx_http_variable_value_t *v, uintptr_t data) | |
499 | 1368 { |
671 | 1369 ngx_str_t path; |
573 | 1370 ngx_http_core_loc_conf_t *clcf; |
509 | 1371 |
1372 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1373 | |
671 | 1374 if (clcf->root_lengths == NULL) { |
1375 v->len = clcf->root.len; | |
1376 v->valid = 1; | |
1565 | 1377 v->no_cacheable = 0; |
671 | 1378 v->not_found = 0; |
1379 v->data = clcf->root.data; | |
1380 | |
1381 } else { | |
1382 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0, | |
1383 clcf->root_values->elts) | |
1384 == NULL) | |
1385 { | |
1386 return NGX_ERROR; | |
1387 } | |
1388 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1389 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
|
1390 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1391 { |
671 | 1392 return NGX_ERROR; |
1393 } | |
1394 | |
1395 v->len = path.len; | |
1396 v->valid = 1; | |
1565 | 1397 v->no_cacheable = 0; |
671 | 1398 v->not_found = 0; |
1399 v->data = path.data; | |
1400 } | |
509 | 1401 |
573 | 1402 return NGX_OK; |
509 | 1403 } |
1404 | |
1405 | |
573 | 1406 static ngx_int_t |
2259 | 1407 ngx_http_variable_realpath_root(ngx_http_request_t *r, |
1408 ngx_http_variable_value_t *v, uintptr_t data) | |
1409 { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1410 u_char *real; |
2259 | 1411 size_t len; |
1412 ngx_str_t path; | |
1413 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
|
1414 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1415 u_char buffer[NGX_MAX_PATH]; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1416 #endif |
2259 | 1417 |
1418 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1419 | |
1420 if (clcf->root_lengths == NULL) { | |
1421 path = clcf->root; | |
1422 | |
1423 } else { | |
1424 if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1, | |
1425 clcf->root_values->elts) | |
1426 == NULL) | |
1427 { | |
1428 return NGX_ERROR; | |
1429 } | |
1430 | |
1431 path.data[path.len - 1] = '\0'; | |
1432 | |
5316
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1433 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
|
1434 != NGX_OK) |
12dd27b74117
Fixed memory leaks in the root and auth_basic_user_file directives.
Valentin Bartenev <vbart@nginx.com>
parents:
5204
diff
changeset
|
1435 { |
2259 | 1436 return NGX_ERROR; |
1437 } | |
1438 } | |
1439 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1440 #if (NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1441 real = buffer; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1442 #else |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1443 real = NULL; |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1444 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1445 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1446 real = ngx_realpath(path.data, real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1447 |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1448 if (real == NULL) { |
2259 | 1449 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
1450 ngx_realpath_n " \"%s\" failed", path.data); | |
1451 return NGX_ERROR; | |
1452 } | |
1453 | |
1454 len = ngx_strlen(real); | |
1455 | |
1456 v->data = ngx_pnalloc(r->pool, len); | |
1457 if (v->data == NULL) { | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1458 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1459 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1460 #endif |
2259 | 1461 return NGX_ERROR; |
1462 } | |
1463 | |
1464 v->len = len; | |
1465 v->valid = 1; | |
1466 v->no_cacheable = 0; | |
1467 v->not_found = 0; | |
1468 | |
1469 ngx_memcpy(v->data, real, len); | |
1470 | |
4558
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1471 #if !(NGX_HAVE_MAX_PATH) |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1472 ngx_free(real); |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1473 #endif |
8865fd1f3aa5
Fixed unconditional MAX_PATH usage (ticket #22).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4545
diff
changeset
|
1474 |
2259 | 1475 return NGX_OK; |
1476 } | |
1477 | |
1478 | |
1479 static ngx_int_t | |
573 | 1480 ngx_http_variable_request_filename(ngx_http_request_t *r, |
1481 ngx_http_variable_value_t *v, uintptr_t data) | |
509 | 1482 { |
773 | 1483 size_t root; |
573 | 1484 ngx_str_t path; |
499 | 1485 |
773 | 1486 if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) { |
573 | 1487 return NGX_ERROR; |
557 | 1488 } |
509 | 1489 |
557 | 1490 /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */ |
509 | 1491 |
573 | 1492 v->len = path.len - 1; |
1493 v->valid = 1; | |
1565 | 1494 v->no_cacheable = 0; |
573 | 1495 v->not_found = 0; |
1496 v->data = path.data; | |
499 | 1497 |
573 | 1498 return NGX_OK; |
499 | 1499 } |
1500 | |
1501 | |
573 | 1502 static ngx_int_t |
1811 | 1503 ngx_http_variable_server_name(ngx_http_request_t *r, |
1504 ngx_http_variable_value_t *v, uintptr_t data) | |
1505 { | |
1506 ngx_http_core_srv_conf_t *cscf; | |
1507 | |
1508 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); | |
1509 | |
1510 v->len = cscf->server_name.len; | |
1511 v->valid = 1; | |
1512 v->no_cacheable = 0; | |
1513 v->not_found = 0; | |
1514 v->data = cscf->server_name.data; | |
1515 | |
1516 return NGX_OK; | |
1517 } | |
1518 | |
1519 | |
1520 static ngx_int_t | |
573 | 1521 ngx_http_variable_request_method(ngx_http_request_t *r, |
1522 ngx_http_variable_value_t *v, uintptr_t data) | |
561 | 1523 { |
647 | 1524 if (r->main->method_name.data) { |
1525 v->len = r->main->method_name.len; | |
573 | 1526 v->valid = 1; |
1565 | 1527 v->no_cacheable = 0; |
573 | 1528 v->not_found = 0; |
647 | 1529 v->data = r->main->method_name.data; |
573 | 1530 |
1531 } else { | |
1532 v->not_found = 1; | |
561 | 1533 } |
1534 | |
573 | 1535 return NGX_OK; |
561 | 1536 } |
1537 | |
1538 | |
573 | 1539 static ngx_int_t |
1540 ngx_http_variable_remote_user(ngx_http_request_t *r, | |
1541 ngx_http_variable_value_t *v, uintptr_t data) | |
539 | 1542 { |
573 | 1543 ngx_int_t rc; |
539 | 1544 |
1545 rc = ngx_http_auth_basic_user(r); | |
1546 | |
1547 if (rc == NGX_DECLINED) { | |
573 | 1548 v->not_found = 1; |
1549 return NGX_OK; | |
539 | 1550 } |
1551 | |
1552 if (rc == NGX_ERROR) { | |
573 | 1553 return NGX_ERROR; |
539 | 1554 } |
1555 | |
573 | 1556 v->len = r->headers_in.user.len; |
1557 v->valid = 1; | |
1565 | 1558 v->no_cacheable = 0; |
573 | 1559 v->not_found = 0; |
1560 v->data = r->headers_in.user.data; | |
571 | 1561 |
573 | 1562 return NGX_OK; |
571 | 1563 } |
1564 | |
1565 | |
611 | 1566 static ngx_int_t |
4886 | 1567 ngx_http_variable_bytes_sent(ngx_http_request_t *r, |
1568 ngx_http_variable_value_t *v, uintptr_t data) | |
1569 { | |
1570 u_char *p; | |
1571 | |
1572 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); | |
1573 if (p == NULL) { | |
1574 return NGX_ERROR; | |
1575 } | |
1576 | |
1577 v->len = ngx_sprintf(p, "%O", r->connection->sent) - p; | |
1578 v->valid = 1; | |
1579 v->no_cacheable = 0; | |
1580 v->not_found = 0; | |
1581 v->data = p; | |
1582 | |
1583 return NGX_OK; | |
1584 } | |
1585 | |
1586 | |
1587 static ngx_int_t | |
611 | 1588 ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
1589 ngx_http_variable_value_t *v, uintptr_t data) | |
1590 { | |
1591 off_t sent; | |
1592 u_char *p; | |
1593 | |
1594 sent = r->connection->sent - r->header_size; | |
1595 | |
1596 if (sent < 0) { | |
1597 sent = 0; | |
1598 } | |
1599 | |
2049 | 1600 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
611 | 1601 if (p == NULL) { |
1602 return NGX_ERROR; | |
1603 } | |
1604 | |
1605 v->len = ngx_sprintf(p, "%O", sent) - p; | |
1606 v->valid = 1; | |
1565 | 1607 v->no_cacheable = 0; |
611 | 1608 v->not_found = 0; |
1609 v->data = p; | |
1610 | |
1611 return NGX_OK; | |
1612 } | |
1613 | |
1614 | |
629 | 1615 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1616 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
|
1617 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
|
1618 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1619 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
|
1620 v->len = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1621 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1622 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1623 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1624 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1625 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1626 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1627 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1628 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1629 static ngx_int_t |
4685
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1630 ngx_http_variable_status(ngx_http_request_t *r, |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1631 ngx_http_variable_value_t *v, uintptr_t data) |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1632 { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1633 ngx_uint_t status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1634 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1635 v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1636 if (v->data == NULL) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1637 return NGX_ERROR; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1638 } |
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 if (r->err_status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1641 status = r->err_status; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1642 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1643 } else if (r->headers_out.status) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1644 status = r->headers_out.status; |
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 } else if (r->http_version == NGX_HTTP_VERSION_9) { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1647 status = 9; |
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 } else { |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1650 status = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1651 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1652 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1653 v->len = ngx_sprintf(v->data, "%03ui", status) - v->data; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1654 v->valid = 1; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1655 v->no_cacheable = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1656 v->not_found = 0; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1657 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1658 return NGX_OK; |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1659 } |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1660 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1661 |
956edecaedeb
New core variable: $status.
Andrey Belov <defan@nginx.com>
parents:
4641
diff
changeset
|
1662 static ngx_int_t |
641 | 1663 ngx_http_variable_sent_content_type(ngx_http_request_t *r, |
1664 ngx_http_variable_value_t *v, uintptr_t data) | |
1665 { | |
1666 if (r->headers_out.content_type.len) { | |
1667 v->len = r->headers_out.content_type.len; | |
1668 v->valid = 1; | |
1565 | 1669 v->no_cacheable = 0; |
641 | 1670 v->not_found = 0; |
1671 v->data = r->headers_out.content_type.data; | |
1672 | |
1673 } else { | |
1674 v->not_found = 1; | |
1675 } | |
1676 | |
1677 return NGX_OK; | |
1678 } | |
1679 | |
1680 | |
1681 static ngx_int_t | |
1682 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
1683 ngx_http_variable_value_t *v, uintptr_t data) | |
1684 { | |
1685 u_char *p; | |
1686 | |
1687 if (r->headers_out.content_length) { | |
1688 v->len = r->headers_out.content_length->value.len; | |
1689 v->valid = 1; | |
1565 | 1690 v->no_cacheable = 0; |
641 | 1691 v->not_found = 0; |
1692 v->data = r->headers_out.content_length->value.data; | |
1693 | |
1694 return NGX_OK; | |
1695 } | |
1696 | |
1697 if (r->headers_out.content_length_n >= 0) { | |
2049 | 1698 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
641 | 1699 if (p == NULL) { |
1700 return NGX_ERROR; | |
1701 } | |
1702 | |
1703 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
1704 v->valid = 1; | |
1565 | 1705 v->no_cacheable = 0; |
641 | 1706 v->not_found = 0; |
1707 v->data = p; | |
1708 | |
1709 return NGX_OK; | |
1710 } | |
1711 | |
1712 v->not_found = 1; | |
1713 | |
1714 return NGX_OK; | |
1715 } | |
1716 | |
1717 | |
1718 static ngx_int_t | |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1719 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
|
1720 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
|
1721 { |
2539
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1722 ngx_str_t name; |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1723 |
2485
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1724 if (r->headers_out.location) { |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1725 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
|
1726 v->valid = 1; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1727 v->no_cacheable = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1728 v->not_found = 0; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1729 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
|
1730 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1731 return NGX_OK; |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1732 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1733 |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3500
diff
changeset
|
1734 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
|
1735 |
051e9b12428e
fix segfault introduced in r2486 in $sent_http_location processing
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1736 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
|
1737 &r->headers_out.headers.part, |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1738 sizeof("sent_http_") - 1); |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1739 } |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1740 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1741 |
51b1097dbb67
fix $sent_http_location for local redirects
Igor Sysoev <igor@sysoev.ru>
parents:
2415
diff
changeset
|
1742 static ngx_int_t |
641 | 1743 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, |
1744 ngx_http_variable_value_t *v, uintptr_t data) | |
1745 { | |
1746 u_char *p; | |
1747 | |
1748 if (r->headers_out.last_modified) { | |
1749 v->len = r->headers_out.last_modified->value.len; | |
1750 v->valid = 1; | |
1565 | 1751 v->no_cacheable = 0; |
641 | 1752 v->not_found = 0; |
1753 v->data = r->headers_out.last_modified->value.data; | |
1754 | |
1755 return NGX_OK; | |
1756 } | |
1757 | |
1758 if (r->headers_out.last_modified_time >= 0) { | |
5434
c21e341c51cb
Removed extra allocation for $sent_http_last_modified.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5361
diff
changeset
|
1759 p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1); |
641 | 1760 if (p == NULL) { |
1761 return NGX_ERROR; | |
1762 } | |
1763 | |
1764 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
1765 v->valid = 1; | |
1565 | 1766 v->no_cacheable = 0; |
641 | 1767 v->not_found = 0; |
1768 v->data = p; | |
1769 | |
1770 return NGX_OK; | |
1771 } | |
1772 | |
1773 v->not_found = 1; | |
1774 | |
1775 return NGX_OK; | |
1776 } | |
1777 | |
1778 | |
1779 static ngx_int_t | |
1780 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
1781 ngx_http_variable_value_t *v, uintptr_t data) | |
1782 { | |
1783 size_t len; | |
1784 char *p; | |
1785 | |
5072
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1786 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
|
1787 len = sizeof("upgrade") - 1; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1788 p = "upgrade"; |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1789 |
7fa7e60a7f66
Proxy: support for connection upgrade (101 Switching Protocols).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5010
diff
changeset
|
1790 } else if (r->keepalive) { |
641 | 1791 len = sizeof("keep-alive") - 1; |
1792 p = "keep-alive"; | |
1793 | |
1794 } else { | |
1795 len = sizeof("close") - 1; | |
1796 p = "close"; | |
1797 } | |
1798 | |
1799 v->len = len; | |
1800 v->valid = 1; | |
1565 | 1801 v->no_cacheable = 0; |
641 | 1802 v->not_found = 0; |
1803 v->data = (u_char *) p; | |
1804 | |
1805 return NGX_OK; | |
1806 } | |
1807 | |
1808 | |
1809 static ngx_int_t | |
1810 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
1811 ngx_http_variable_value_t *v, uintptr_t data) | |
1812 { | |
1813 u_char *p; | |
1814 ngx_http_core_loc_conf_t *clcf; | |
1815 | |
1816 if (r->keepalive) { | |
1817 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1818 | |
1819 if (clcf->keepalive_header) { | |
1820 | |
2049 | 1821 p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); |
641 | 1822 if (p == NULL) { |
1823 return NGX_ERROR; | |
1824 } | |
1825 | |
1826 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
1827 v->valid = 1; | |
1565 | 1828 v->no_cacheable = 0; |
641 | 1829 v->not_found = 0; |
1830 v->data = p; | |
1831 | |
1832 return NGX_OK; | |
1833 } | |
1834 } | |
1835 | |
1836 v->not_found = 1; | |
1837 | |
1838 return NGX_OK; | |
1839 } | |
1840 | |
1841 | |
1842 static ngx_int_t | |
1843 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
1844 ngx_http_variable_value_t *v, uintptr_t data) | |
1845 { | |
1846 if (r->chunked) { | |
1847 v->len = sizeof("chunked") - 1; | |
1848 v->valid = 1; | |
1565 | 1849 v->no_cacheable = 0; |
641 | 1850 v->not_found = 0; |
1851 v->data = (u_char *) "chunked"; | |
1852 | |
1853 } else { | |
1854 v->not_found = 1; | |
1855 } | |
1856 | |
1857 return NGX_OK; | |
1858 } | |
1859 | |
1860 | |
1861 static ngx_int_t | |
629 | 1862 ngx_http_variable_request_completion(ngx_http_request_t *r, |
1863 ngx_http_variable_value_t *v, uintptr_t data) | |
1864 { | |
1865 if (r->request_complete) { | |
1866 v->len = 2; | |
1867 v->valid = 1; | |
1565 | 1868 v->no_cacheable = 0; |
629 | 1869 v->not_found = 0; |
1870 v->data = (u_char *) "OK"; | |
1871 | |
1872 return NGX_OK; | |
1873 } | |
1874 | |
1875 v->len = 0; | |
1876 v->valid = 1; | |
1565 | 1877 v->no_cacheable = 0; |
629 | 1878 v->not_found = 0; |
1879 v->data = (u_char *) ""; | |
1880 | |
1881 return NGX_OK; | |
1882 } | |
1883 | |
1884 | |
759 | 1885 static ngx_int_t |
2844 | 1886 ngx_http_variable_request_body(ngx_http_request_t *r, |
1887 ngx_http_variable_value_t *v, uintptr_t data) | |
1888 { | |
1889 u_char *p; | |
1890 size_t len; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1891 ngx_buf_t *buf; |
2844 | 1892 ngx_chain_t *cl; |
1893 | |
2878
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1894 if (r->request_body == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1895 || r->request_body->bufs == NULL |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1896 || r->request_body->temp_file) |
8535736ace1a
fix segfault introduced in r2845
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
1897 { |
2844 | 1898 v->not_found = 1; |
1899 | |
1900 return NGX_OK; | |
1901 } | |
1902 | |
1903 cl = r->request_body->bufs; | |
1904 buf = cl->buf; | |
1905 | |
1906 if (cl->next == NULL) { | |
1907 v->len = buf->last - buf->pos; | |
1908 v->valid = 1; | |
1909 v->no_cacheable = 0; | |
1910 v->not_found = 0; | |
1911 v->data = buf->pos; | |
1912 | |
1913 return NGX_OK; | |
1914 } | |
1915 | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1916 len = buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1917 cl = cl->next; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1918 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1919 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1920 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1921 len += buf->last - buf->pos; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1922 } |
2844 | 1923 |
1924 p = ngx_pnalloc(r->pool, len); | |
1925 if (p == NULL) { | |
1926 return NGX_ERROR; | |
1927 } | |
1928 | |
1929 v->data = p; | |
4921
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1930 cl = r->request_body->bufs; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1931 |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1932 for ( /* void */ ; cl; cl = cl->next) { |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1933 buf = cl->buf; |
fbc0791bebb2
Request body: $request_body variable generalization.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4913
diff
changeset
|
1934 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
|
1935 } |
2844 | 1936 |
1937 v->len = len; | |
1938 v->valid = 1; | |
1939 v->no_cacheable = 0; | |
1940 v->not_found = 0; | |
1941 | |
1942 return NGX_OK; | |
1943 } | |
1944 | |
1945 | |
1946 static ngx_int_t | |
759 | 1947 ngx_http_variable_request_body_file(ngx_http_request_t *r, |
1948 ngx_http_variable_value_t *v, uintptr_t data) | |
1949 { | |
1950 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
|
1951 v->not_found = 1; |
759 | 1952 |
1953 return NGX_OK; | |
1954 } | |
1955 | |
1956 v->len = r->request_body->temp_file->file.name.len; | |
1957 v->valid = 1; | |
1565 | 1958 v->no_cacheable = 0; |
759 | 1959 v->not_found = 0; |
1960 v->data = r->request_body->temp_file->file.name.data; | |
1961 | |
1962 return NGX_OK; | |
1963 } | |
1964 | |
1965 | |
1329 | 1966 static ngx_int_t |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1967 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
|
1968 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
|
1969 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1970 u_char *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 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
|
1973 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1974 return NGX_ERROR; |
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 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1977 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
|
1978 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1979 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1980 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1981 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1982 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1983 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1984 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1985 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1986 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
1987 static ngx_int_t |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1988 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
|
1989 ngx_http_variable_value_t *v, uintptr_t data) |
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 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1992 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1993 ngx_msec_int_t ms; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1994 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1995 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
|
1996 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1997 return NGX_ERROR; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1998 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
1999 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2000 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2001 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2002 ms = (ngx_msec_int_t) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2003 ((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
|
2004 ms = ngx_max(ms, 0); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2005 |
5361
7094d6da2806
Win32: $request_time fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5327
diff
changeset
|
2006 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
|
2007 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2008 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2009 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2010 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2011 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2012 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2013 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2014 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2015 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2016 static ngx_int_t |
4893
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2017 ngx_http_variable_connection(ngx_http_request_t *r, |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2018 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2019 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2020 u_char *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 p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2023 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2024 return NGX_ERROR; |
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 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2027 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
|
2028 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2029 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2030 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2031 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2032 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2033 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2034 } |
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 static ngx_int_t |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2038 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
|
2039 ngx_http_variable_value_t *v, uintptr_t data) |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2040 { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2041 u_char *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 p = ngx_pnalloc(r->pool, NGX_INT_T_LEN); |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2044 if (p == NULL) { |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2045 return NGX_ERROR; |
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 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2048 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
|
2049 v->valid = 1; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2050 v->no_cacheable = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2051 v->not_found = 0; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2052 v->data = p; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2053 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2054 return NGX_OK; |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2055 } |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2056 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2057 |
e89bd9896fea
Variables $connection and $connection_requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4886
diff
changeset
|
2058 static ngx_int_t |
1329 | 2059 ngx_http_variable_nginx_version(ngx_http_request_t *r, |
2060 ngx_http_variable_value_t *v, uintptr_t data) | |
2061 { | |
2062 v->len = sizeof(NGINX_VERSION) - 1; | |
2063 v->valid = 1; | |
1565 | 2064 v->no_cacheable = 0; |
1329 | 2065 v->not_found = 0; |
2066 v->data = (u_char *) NGINX_VERSION; | |
2067 | |
2068 return NGX_OK; | |
2069 } | |
2070 | |
2071 | |
2011 | 2072 static ngx_int_t |
2073 ngx_http_variable_hostname(ngx_http_request_t *r, | |
2074 ngx_http_variable_value_t *v, uintptr_t data) | |
2075 { | |
2076 v->len = ngx_cycle->hostname.len; | |
2077 v->valid = 1; | |
2078 v->no_cacheable = 0; | |
2079 v->not_found = 0; | |
2080 v->data = ngx_cycle->hostname.data; | |
2081 | |
2082 return NGX_OK; | |
2083 } | |
2084 | |
2085 | |
2249 | 2086 static ngx_int_t |
2087 ngx_http_variable_pid(ngx_http_request_t *r, | |
2088 ngx_http_variable_value_t *v, uintptr_t data) | |
2089 { | |
2090 u_char *p; | |
2091 | |
2092 p = ngx_pnalloc(r->pool, NGX_INT64_LEN); | |
2093 if (p == NULL) { | |
2094 return NGX_ERROR; | |
2095 } | |
2096 | |
2097 v->len = ngx_sprintf(p, "%P", ngx_pid) - p; | |
2098 v->valid = 1; | |
2099 v->no_cacheable = 0; | |
2100 v->not_found = 0; | |
2101 v->data = p; | |
2102 | |
2103 return NGX_OK; | |
2104 } | |
2105 | |
2106 | |
4913
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2107 static ngx_int_t |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2108 ngx_http_variable_msec(ngx_http_request_t *r, |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2109 ngx_http_variable_value_t *v, uintptr_t data) |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2110 { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2111 u_char *p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2112 ngx_time_t *tp; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2113 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2114 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
|
2115 if (p == NULL) { |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2116 return NGX_ERROR; |
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 tp = ngx_timeofday(); |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2120 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2121 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
|
2122 v->valid = 1; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2123 v->no_cacheable = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2124 v->not_found = 0; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2125 v->data = p; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2126 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2127 return NGX_OK; |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2128 } |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2129 |
002f2c783d7c
Variables $request_time and $msec.
Ruslan Ermilov <ru@nginx.com>
parents:
4893
diff
changeset
|
2130 |
5010
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2131 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2132 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
|
2133 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
|
2134 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2135 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2136 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2137 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
|
2138 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2139 return NGX_ERROR; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2140 } |
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 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
|
2143 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
|
2144 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2145 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
|
2146 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2147 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2148 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2149 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2150 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2151 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2152 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2153 |
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 static ngx_int_t |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2156 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
|
2157 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
|
2158 { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2159 u_char *p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2160 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2161 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
|
2162 if (p == NULL) { |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2163 return NGX_ERROR; |
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 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
|
2167 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2168 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
|
2169 v->valid = 1; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2170 v->no_cacheable = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2171 v->not_found = 0; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2172 v->data = p; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2173 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2174 return NGX_OK; |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2175 } |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2176 |
829cc5872186
Variables $pipe, $request_length, $time_iso8601, and $time_local.
Ruslan Ermilov <ru@nginx.com>
parents:
4972
diff
changeset
|
2177 |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2178 void * |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2179 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
|
2180 { |
3929
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2181 void *value; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2182 u_char *low; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2183 size_t len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2184 ngx_uint_t key; |
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 len = match->len; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2187 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2188 if (len) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2189 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
|
2190 if (low == NULL) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2191 return NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2192 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2193 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2194 } else { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2195 low = NULL; |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2196 } |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2197 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2198 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
|
2199 |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2200 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
|
2201 if (value) { |
fa4612bfb9fa
change ngx_http_map_find(): use case sensitive regexes
Igor Sysoev <igor@sysoev.ru>
parents:
3872
diff
changeset
|
2202 return value; |
3872
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2203 } |
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 #if (NGX_PCRE) |
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 (len && map->nregex) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2208 ngx_int_t n; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2209 ngx_uint_t i; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2210 ngx_http_map_regex_t *reg; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2211 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2212 reg = map->regex; |
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 for (i = 0; i < map->nregex; i++) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2215 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2216 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
|
2217 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2218 if (n == NGX_OK) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2219 return reg[i].value; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2220 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2221 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2222 if (n == NGX_DECLINED) { |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2223 continue; |
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 /* NGX_ERROR */ |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2227 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2228 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2229 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2230 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2231 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2232 #endif |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2233 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2234 return NULL; |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2235 } |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2236 |
83cd1910329c
allow regex as "map" parameter
Igor Sysoev <igor@sysoev.ru>
parents:
3641
diff
changeset
|
2237 |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2238 #if (NGX_PCRE) |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2239 |
3325 | 2240 static ngx_int_t |
2241 ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v, | |
2242 uintptr_t data) | |
2243 { | |
2244 v->not_found = 1; | |
2245 return NGX_OK; | |
2246 } | |
2247 | |
2248 | |
2249 ngx_http_regex_t * | |
2250 ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc) | |
2251 { | |
2252 u_char *p; | |
2253 size_t size; | |
2254 ngx_str_t name; | |
2255 ngx_uint_t i, n; | |
2256 ngx_http_variable_t *v; | |
2257 ngx_http_regex_t *re; | |
2258 ngx_http_regex_variable_t *rv; | |
2259 ngx_http_core_main_conf_t *cmcf; | |
2260 | |
2261 rc->pool = cf->pool; | |
2262 | |
2263 if (ngx_regex_compile(rc) != NGX_OK) { | |
2264 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err); | |
2265 return NULL; | |
2266 } | |
2267 | |
2268 re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t)); | |
2269 if (re == NULL) { | |
2270 return NULL; | |
2271 } | |
2272 | |
2273 re->regex = rc->regex; | |
2274 re->ncaptures = rc->captures; | |
5204
a64c8a5da336
PCRE: retain input pattern for all regular expressions.
Piotr Sikora <piotr@cloudflare.com>
parents:
5084
diff
changeset
|
2275 re->name = rc->pattern; |
3325 | 2276 |
2277 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2278 cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures); | |
2279 | |
2280 n = (ngx_uint_t) rc->named_captures; | |
2281 | |
2282 if (n == 0) { | |
2283 return re; | |
2284 } | |
2285 | |
2286 rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t)); | |
2287 if (rv == NULL) { | |
2288 return NULL; | |
2289 } | |
2290 | |
2291 re->variables = rv; | |
2292 re->nvariables = n; | |
2293 | |
2294 size = rc->name_size; | |
2295 p = rc->names; | |
2296 | |
2297 for (i = 0; i < n; i++) { | |
2298 rv[i].capture = 2 * ((p[0] << 8) + p[1]); | |
2299 | |
2300 name.data = &p[2]; | |
2301 name.len = ngx_strlen(name.data); | |
2302 | |
2303 v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE); | |
2304 if (v == NULL) { | |
2305 return NULL; | |
2306 } | |
2307 | |
2308 rv[i].index = ngx_http_get_variable_index(cf, &name); | |
2309 if (rv[i].index == NGX_ERROR) { | |
2310 return NULL; | |
2311 } | |
2312 | |
2313 v->get_handler = ngx_http_variable_not_found; | |
2314 | |
3409
bb79608169eb
named captures worked for two names only
Igor Sysoev <igor@sysoev.ru>
parents:
3356
diff
changeset
|
2315 p += size; |
3325 | 2316 } |
2317 | |
2318 return re; | |
2319 } | |
2320 | |
2321 | |
2322 ngx_int_t | |
2323 ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s) | |
2324 { | |
2325 ngx_int_t rc, index; | |
2326 ngx_uint_t i, n, len; | |
2327 ngx_http_variable_value_t *vv; | |
2328 ngx_http_core_main_conf_t *cmcf; | |
2329 | |
2330 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
2331 | |
2332 if (re->ncaptures) { | |
3345
d8228f0b5113
evaluate maximum captures size on configuration phase
Igor Sysoev <igor@sysoev.ru>
parents:
3344
diff
changeset
|
2333 len = cmcf->ncaptures; |
3325 | 2334 |
2335 if (r->captures == NULL) { | |
2336 r->captures = ngx_palloc(r->pool, len * sizeof(int)); | |
2337 if (r->captures == NULL) { | |
2338 return NGX_ERROR; | |
2339 } | |
2340 } | |
2341 | |
2342 } else { | |
2343 len = 0; | |
2344 } | |
2345 | |
2346 rc = ngx_regex_exec(re->regex, s, r->captures, len); | |
2347 | |
2348 if (rc == NGX_REGEX_NO_MATCHED) { | |
2349 return NGX_DECLINED; | |
2350 } | |
2351 | |
2352 if (rc < 0) { | |
2353 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, | |
2354 ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"", | |
2355 rc, s, &re->name); | |
2356 return NGX_ERROR; | |
2357 } | |
2358 | |
2359 for (i = 0; i < re->nvariables; i++) { | |
2360 | |
2361 n = re->variables[i].capture; | |
2362 index = re->variables[i].index; | |
2363 vv = &r->variables[index]; | |
2364 | |
2365 vv->len = r->captures[n + 1] - r->captures[n]; | |
2366 vv->valid = 1; | |
2367 vv->no_cacheable = 0; | |
2368 vv->not_found = 0; | |
2369 vv->data = &s->data[r->captures[n]]; | |
2370 | |
2371 #if (NGX_DEBUG) | |
2372 { | |
2373 ngx_http_variable_t *v; | |
2374 | |
2375 v = cmcf->variables.elts; | |
2376 | |
2377 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
2378 "http regex set $%V to \"%*s\"", | |
2379 &v[index].name, vv->len, vv->data); | |
2380 } | |
2381 #endif | |
2382 } | |
2383 | |
3344
1aed55182ea2
fix captures in "rewrite", the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3325
diff
changeset
|
2384 r->ncaptures = rc * 2; |
3325 | 2385 r->captures_data = s->data; |
2386 | |
2387 return NGX_OK; | |
2388 } | |
2389 | |
3356
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2390 #endif |
fe08c14530e9
fix building without PCRE, the bug had been introduced in r3326
Igor Sysoev <igor@sysoev.ru>
parents:
3345
diff
changeset
|
2391 |
3325 | 2392 |
499 | 2393 ngx_int_t |
509 | 2394 ngx_http_variables_add_core_vars(ngx_conf_t *cf) |
499 | 2395 { |
611 | 2396 ngx_int_t rc; |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2397 ngx_http_variable_t *cv, *v; |
501 | 2398 ngx_http_core_main_conf_t *cmcf; |
499 | 2399 |
509 | 2400 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); |
2401 | |
611 | 2402 cmcf->variables_keys = ngx_pcalloc(cf->temp_pool, |
2403 sizeof(ngx_hash_keys_arrays_t)); | |
2404 if (cmcf->variables_keys == NULL) { | |
2405 return NGX_ERROR; | |
2406 } | |
2407 | |
2408 cmcf->variables_keys->pool = cf->pool; | |
2409 cmcf->variables_keys->temp_pool = cf->pool; | |
2410 | |
2411 if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL) | |
2412 != NGX_OK) | |
509 | 2413 { |
499 | 2414 return NGX_ERROR; |
2415 } | |
2416 | |
4641
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2417 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
|
2418 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
|
2419 if (v == NULL) { |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2420 return NGX_ERROR; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2421 } |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2422 |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2423 *v = *cv; |
045bb3ef3ffc
Fixed core variables dynamic access after reconfiguration.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4572
diff
changeset
|
2424 |
611 | 2425 rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, |
2426 NGX_HASH_READONLY_KEY); | |
2427 | |
2428 if (rc == NGX_OK) { | |
2429 continue; | |
499 | 2430 } |
2431 | |
611 | 2432 if (rc == NGX_BUSY) { |
2433 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
2434 "conflicting variable name \"%V\"", &v->name); | |
2435 } | |
2436 | |
2437 return NGX_ERROR; | |
499 | 2438 } |
2439 | |
2440 return NGX_OK; | |
2441 } | |
509 | 2442 |
2443 | |
2444 ngx_int_t | |
2445 ngx_http_variables_init_vars(ngx_conf_t *cf) | |
2446 { | |
2447 ngx_uint_t i, n; | |
611 | 2448 ngx_hash_key_t *key; |
2449 ngx_hash_init_t hash; | |
509 | 2450 ngx_http_variable_t *v, *av; |
2451 ngx_http_core_main_conf_t *cmcf; | |
2452 | |
2453 /* set the handlers for the indexed http variables */ | |
2454 | |
2455 cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); | |
2456 | |
2457 v = cmcf->variables.elts; | |
611 | 2458 key = cmcf->variables_keys->keys.elts; |
509 | 2459 |
2460 for (i = 0; i < cmcf->variables.nelts; i++) { | |
2461 | |
611 | 2462 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
509 | 2463 |
1191
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2464 av = key[n].value; |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2465 |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2466 if (av->get_handler |
0eb2dc4fdea8
fix segfault introduced in r1190
Igor Sysoev <igor@sysoev.ru>
parents:
1173
diff
changeset
|
2467 && v[i].name.len == key[n].key.len |
611 | 2468 && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len) |
509 | 2469 == 0) |
2470 { | |
637 | 2471 v[i].get_handler = av->get_handler; |
611 | 2472 v[i].data = av->data; |
527 | 2473 |
611 | 2474 av->flags |= NGX_HTTP_VAR_INDEXED; |
2475 v[i].flags = av->flags; | |
509 | 2476 |
611 | 2477 av->index = i; |
533 | 2478 |
509 | 2479 goto next; |
2480 } | |
2481 } | |
2482 | |
2483 if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) { | |
637 | 2484 v[i].get_handler = ngx_http_variable_unknown_header_in; |
577 | 2485 v[i].data = (uintptr_t) &v[i].name; |
2486 | |
2487 continue; | |
2488 } | |
2489 | |
2490 if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) { | |
637 | 2491 v[i].get_handler = ngx_http_variable_unknown_header_out; |
509 | 2492 v[i].data = (uintptr_t) &v[i].name; |
2493 | |
2494 continue; | |
2495 } | |
2496 | |
1162 | 2497 if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) { |
2498 v[i].get_handler = ngx_http_upstream_header_variable; | |
2499 v[i].data = (uintptr_t) &v[i].name; | |
1565 | 2500 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
1162 | 2501 |
2502 continue; | |
2503 } | |
2504 | |
2307 | 2505 if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) { |
2506 v[i].get_handler = ngx_http_variable_cookie; | |
2507 v[i].data = (uintptr_t) &v[i].name; | |
2508 | |
2509 continue; | |
2510 } | |
2511 | |
2137 | 2512 if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) { |
2513 v[i].get_handler = ngx_http_variable_argument; | |
2514 v[i].data = (uintptr_t) &v[i].name; | |
3499
b4a14d50388b
make $arg_ variables non-cacheable
Igor Sysoev <igor@sysoev.ru>
parents:
3463
diff
changeset
|
2515 v[i].flags = NGX_HTTP_VAR_NOCACHEABLE; |
2137 | 2516 |
2517 continue; | |
2518 } | |
2519 | |
509 | 2520 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
2521 "unknown \"%V\" variable", &v[i].name); | |
2522 | |
2523 return NGX_ERROR; | |
2524 | |
2525 next: | |
2526 continue; | |
2527 } | |
2528 | |
2529 | |
611 | 2530 for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) { |
2531 av = key[n].value; | |
2532 | |
2533 if (av->flags & NGX_HTTP_VAR_NOHASH) { | |
2534 key[n].key.data = NULL; | |
583 | 2535 } |
2536 } | |
2537 | |
2538 | |
611 | 2539 hash.hash = &cmcf->variables_hash; |
2540 hash.key = ngx_hash_key; | |
2541 hash.max_size = cmcf->variables_hash_max_size; | |
2542 hash.bucket_size = cmcf->variables_hash_bucket_size; | |
2543 hash.name = "variables_hash"; | |
2544 hash.pool = cf->pool; | |
2545 hash.temp_pool = NULL; | |
509 | 2546 |
611 | 2547 if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts, |
2548 cmcf->variables_keys->keys.nelts) | |
581 | 2549 != NGX_OK) |
509 | 2550 { |
2551 return NGX_ERROR; | |
2552 } | |
2553 | |
611 | 2554 cmcf->variables_keys = NULL; |
509 | 2555 |
2556 return NGX_OK; | |
2557 } |