comparison src/http/ngx_http_variables.c @ 64:5db440287648 NGINX_0_1_32

nginx 0.1.32 *) Bugfix: the arguments were omitted in the redirects, issued by the "rewrite" directive; bug appeared in 0.1.29. *) Feature: the "if" directive supports the captures in regular expressions. *) Feature: the "set" directive supports the variables and the captures of regular expressions. *) Feature: the "X-Accel-Redirect" response header line is supported in proxy and FastCGI mode.
author Igor Sysoev <http://sysoev.ru>
date Thu, 19 May 2005 00:00:00 +0400
parents b55cbf18157e
children 056fd0e5a5a6
comparison
equal deleted inserted replaced
63:e42867135781 64:5db440287648
12 12
13 static ngx_http_variable_value_t * 13 static ngx_http_variable_value_t *
14 ngx_http_variable_request(ngx_http_request_t *r, uintptr_t data); 14 ngx_http_variable_request(ngx_http_request_t *r, uintptr_t data);
15 static ngx_http_variable_value_t * 15 static ngx_http_variable_value_t *
16 ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data); 16 ngx_http_variable_header(ngx_http_request_t *r, uintptr_t data);
17 static ngx_http_variable_value_t *
18 ngx_http_variable_headers(ngx_http_request_t *r, uintptr_t data);
17 static ngx_http_variable_value_t * 19 static ngx_http_variable_value_t *
18 ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data); 20 ngx_http_variable_unknown_header(ngx_http_request_t *r, uintptr_t data);
19 static ngx_http_variable_value_t * 21 static ngx_http_variable_value_t *
20 ngx_http_variable_host(ngx_http_request_t *r, uintptr_t data); 22 ngx_http_variable_host(ngx_http_request_t *r, uintptr_t data);
21 static ngx_http_variable_value_t * 23 static ngx_http_variable_value_t *
61 #if (NGX_HTTP_PROXY) 63 #if (NGX_HTTP_PROXY)
62 { ngx_string("http_x_forwarded_for"), ngx_http_variable_header, 64 { ngx_string("http_x_forwarded_for"), ngx_http_variable_header,
63 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0 }, 65 offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0 },
64 #endif 66 #endif
65 67
68 { ngx_string("http_cookie"), ngx_http_variable_headers,
69 offsetof(ngx_http_request_t, headers_in.cookies), 0 },
70
66 { ngx_string("content_length"), ngx_http_variable_header, 71 { ngx_string("content_length"), ngx_http_variable_header,
67 offsetof(ngx_http_request_t, headers_in.content_length), 0 }, 72 offsetof(ngx_http_request_t, headers_in.content_length), 0 },
68 73
69 { ngx_string("content_type"), ngx_http_variable_header, 74 { ngx_string("content_type"), ngx_http_variable_header,
70 offsetof(ngx_http_request_t, headers_in.content_type), 0 }, 75 offsetof(ngx_http_request_t, headers_in.content_type), 0 },
326 return NULL; 331 return NULL;
327 } 332 }
328 333
329 vv->value = 0; 334 vv->value = 0;
330 vv->text = h->value; 335 vv->text = h->value;
336
337 return vv;
338 }
339
340
341 static ngx_http_variable_value_t *
342 ngx_http_variable_headers(ngx_http_request_t *r, uintptr_t data)
343 {
344 u_char *p;
345 ngx_uint_t i;
346 ngx_array_t *a;
347 ngx_table_elt_t **h;
348 ngx_http_variable_value_t *vv;
349
350 a = (ngx_array_t *) ((char *) r + data);
351
352 if (a->nelts == 0) {
353 return NGX_HTTP_VAR_NOT_FOUND;
354 }
355
356 vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
357 if (vv == NULL) {
358 return NULL;
359 }
360
361 vv->value = 0;
362
363 h = a->elts;
364
365 if (a->nelts == 1) {
366 vv->text = (*h)->value;
367 return vv;
368 }
369
370 vv->text.len = (size_t) - (ssize_t) (sizeof("; ") - 1);
371
372 for (i = 0; i < a->nelts; i++) {
373 vv->text.len += h[i]->value.len + sizeof("; ") - 1;
374 }
375
376 vv->text.data = ngx_palloc(r->pool, vv->text.len);
377 if (vv->text.data == NULL) {
378 return NULL;
379 }
380
381 p = vv->text.data;
382
383 for (i = 0; /* void */ ; i++) {
384 p = ngx_cpymem(p, h[i]->value.data, h[i]->value.len);
385
386 if (i == a->nelts - 1) {
387 break;
388 }
389
390 *p++ = ';'; *p++ = ' ';
391 }
331 392
332 return vv; 393 return vv;
333 } 394 }
334 395
335 396