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