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