comparison src/http/modules/ngx_http_headers_filter_module.c @ 464:c8cfb6c462ef NGINX_0_7_44

nginx 0.7.44 *) Feature: the ngx_http_proxy_module preliminary cache support. *) Feature: the --with-pcre option in the configure. *) Feature: the "try_files" directive is now allowed on the server block level. *) Bugfix: the "try_files" directive handled incorrectly a query string in a fallback parameter. *) Bugfix: the "try_files" directive might test incorrectly directories. *) Bugfix: if there is the single server for given address:port pair, then captures in regular expressions in a "server_name" directive did not work.
author Igor Sysoev <http://sysoev.ru>
date Mon, 23 Mar 2009 00:00:00 +0300
parents dac47e9ef0d5
children 9eda3153223b
comparison
equal deleted inserted replaced
463:51cb914e6d3a 464:c8cfb6c462ef
14 typedef ngx_int_t (*ngx_http_set_header_pt)(ngx_http_request_t *r, 14 typedef ngx_int_t (*ngx_http_set_header_pt)(ngx_http_request_t *r,
15 ngx_http_header_val_t *hv, ngx_str_t *value); 15 ngx_http_header_val_t *hv, ngx_str_t *value);
16 16
17 17
18 typedef struct { 18 typedef struct {
19 ngx_str_t name; 19 ngx_str_t name;
20 ngx_uint_t offset; 20 ngx_uint_t offset;
21 ngx_http_set_header_pt handler; 21 ngx_http_set_header_pt handler;
22 } ngx_http_set_header_t; 22 } ngx_http_set_header_t;
23 23
24 24
25 struct ngx_http_header_val_s { 25 struct ngx_http_header_val_s {
26 ngx_table_elt_t value; 26 ngx_http_complex_value_t value;
27 ngx_uint_t offset; 27 ngx_uint_t hash;
28 ngx_http_set_header_pt handler; 28 ngx_str_t key;
29 ngx_array_t *lengths; 29 ngx_http_set_header_pt handler;
30 ngx_array_t *values; 30 ngx_uint_t offset;
31 }; 31 };
32 32
33 33
34 #define NGX_HTTP_EXPIRES_OFF 0 34 #define NGX_HTTP_EXPIRES_OFF 0
35 #define NGX_HTTP_EXPIRES_EPOCH 1 35 #define NGX_HTTP_EXPIRES_EPOCH 1
160 160
161 if (conf->headers) { 161 if (conf->headers) {
162 h = conf->headers->elts; 162 h = conf->headers->elts;
163 for (i = 0; i < conf->headers->nelts; i++) { 163 for (i = 0; i < conf->headers->nelts; i++) {
164 164
165 if (h[i].lengths == NULL) { 165 if (ngx_http_complex_value(r, &h[i].value, &value) != NGX_OK) {
166 value = h[i].value.value; 166 return NGX_ERROR;
167
168 } else {
169 if (ngx_http_script_run(r, &value, h[i].lengths->elts, 0,
170 h[i].values->elts)
171 == NULL)
172 {
173 return NGX_ERROR;
174 }
175 } 167 }
176 168
177 if (h[i].handler(r, &h[i], &value) != NGX_OK) { 169 if (h[i].handler(r, &h[i], &value) != NGX_OK) {
178 return NGX_ERROR; 170 return NGX_ERROR;
179 } 171 }
329 h = ngx_list_push(&r->headers_out.headers); 321 h = ngx_list_push(&r->headers_out.headers);
330 if (h == NULL) { 322 if (h == NULL) {
331 return NGX_ERROR; 323 return NGX_ERROR;
332 } 324 }
333 325
334 h->hash = hv->value.hash; 326 h->hash = hv->hash;
335 h->key = hv->value.key; 327 h->key = hv->key;
336 h->value = *value; 328 h->value = *value;
337 } 329 }
338 330
339 return NGX_OK; 331 return NGX_OK;
340 } 332 }
412 h->hash = 0; 404 h->hash = 0;
413 return NGX_OK; 405 return NGX_OK;
414 } 406 }
415 } 407 }
416 408
417 h->hash = hv->value.hash; 409 h->hash = hv->hash;
418 h->key = hv->value.key; 410 h->key = hv->key;
419 h->value = *value; 411 h->value = *value;
420 412
421 return NGX_OK; 413 return NGX_OK;
422 } 414 }
423 415
576 static char * 568 static char *
577 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 569 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
578 { 570 {
579 ngx_http_headers_conf_t *hcf = conf; 571 ngx_http_headers_conf_t *hcf = conf;
580 572
581 ngx_int_t n; 573 ngx_str_t *value;
582 ngx_str_t *value; 574 ngx_uint_t i;
583 ngx_uint_t i; 575 ngx_http_header_val_t *hv;
584 ngx_http_header_val_t *h; 576 ngx_http_set_header_t *set;
585 ngx_http_set_header_t *sh; 577 ngx_http_compile_complex_value_t ccv;
586 ngx_http_script_compile_t sc;
587 578
588 value = cf->args->elts; 579 value = cf->args->elts;
589 580
590 if (hcf->headers == NULL) { 581 if (hcf->headers == NULL) {
591 hcf->headers = ngx_array_create(cf->pool, 1, 582 hcf->headers = ngx_array_create(cf->pool, 1,
593 if (hcf->headers == NULL) { 584 if (hcf->headers == NULL) {
594 return NGX_CONF_ERROR; 585 return NGX_CONF_ERROR;
595 } 586 }
596 } 587 }
597 588
598 h = ngx_array_push(hcf->headers); 589 hv = ngx_array_push(hcf->headers);
599 if (h == NULL) { 590 if (hv == NULL) {
600 return NGX_CONF_ERROR; 591 return NGX_CONF_ERROR;
601 } 592 }
602 593
603 h->value.hash = 1; 594 hv->hash = 1;
604 h->value.key = value[1]; 595 hv->key = value[1];
605 h->value.value = value[2]; 596 hv->handler = ngx_http_add_header;
606 h->offset = 0; 597 hv->offset = 0;
607 h->handler = ngx_http_add_header; 598
608 h->lengths = NULL; 599 set = ngx_http_set_headers;
609 h->values = NULL; 600 for (i = 0; set[i].name.len; i++) {
610 601 if (ngx_strcasecmp(value[1].data, set[i].name.data) != 0) {
611 sh = ngx_http_set_headers;
612 for (i = 0; sh[i].name.len; i++) {
613 if (ngx_strcasecmp(value[1].data, sh[i].name.data) != 0) {
614 continue; 602 continue;
615 } 603 }
616 604
617 h->offset = sh[i].offset; 605 hv->offset = set[i].offset;
618 h->handler = sh[i].handler; 606 hv->handler = set[i].handler;
607
619 break; 608 break;
620 } 609 }
621 610
622 n = ngx_http_script_variables_count(&value[2]); 611 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
623 612
624 if (n == 0) { 613 ccv.cf = cf;
625 return NGX_CONF_OK; 614 ccv.value = &value[2];
626 } 615 ccv.complex_value = &hv->value;
627 616
628 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); 617 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
629
630 sc.cf = cf;
631 sc.source = &value[2];
632 sc.lengths = &h->lengths;
633 sc.values = &h->values;
634 sc.variables = n;
635 sc.complete_lengths = 1;
636 sc.complete_values = 1;
637
638 if (ngx_http_script_compile(&sc) != NGX_OK) {
639 return NGX_CONF_ERROR; 618 return NGX_CONF_ERROR;
640 } 619 }
641 620
642 return NGX_CONF_OK; 621 return NGX_CONF_OK;
643 } 622 }