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