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