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