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