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