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