comparison src/http/modules/ngx_http_headers_filter_module.c @ 680:597573166f34 NGINX_1_3_3

nginx 1.3.3 *) Feature: entity tags support and the "etag" directive. *) Bugfix: trailing dot in a source value was not ignored if the "map" directive was used with the "hostnames" parameter. *) Bugfix: incorrect location might be used to process a request if a URI was changed via a "rewrite" directive before an internal redirect to a named location.
author Igor Sysoev <http://sysoev.ru>
date Tue, 10 Jul 2012 00:00:00 +0400
parents 9fbf3ad94cbf
children 88a1b4797f2e
comparison
equal deleted inserted replaced
679:cad34cec7d3b 680:597573166f34
55 ngx_http_header_val_t *hv, ngx_str_t *value); 55 ngx_http_header_val_t *hv, ngx_str_t *value);
56 static ngx_int_t ngx_http_add_header(ngx_http_request_t *r, 56 static ngx_int_t ngx_http_add_header(ngx_http_request_t *r,
57 ngx_http_header_val_t *hv, ngx_str_t *value); 57 ngx_http_header_val_t *hv, ngx_str_t *value);
58 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r, 58 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r,
59 ngx_http_header_val_t *hv, ngx_str_t *value); 59 ngx_http_header_val_t *hv, ngx_str_t *value);
60 static ngx_int_t ngx_http_set_response_header(ngx_http_request_t *r,
61 ngx_http_header_val_t *hv, ngx_str_t *value);
60 62
61 static void *ngx_http_headers_create_conf(ngx_conf_t *cf); 63 static void *ngx_http_headers_create_conf(ngx_conf_t *cf);
62 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf, 64 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf,
63 void *parent, void *child); 65 void *parent, void *child);
64 static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf); 66 static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf);
70 72
71 static ngx_http_set_header_t ngx_http_set_headers[] = { 73 static ngx_http_set_header_t ngx_http_set_headers[] = {
72 74
73 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control }, 75 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control },
74 76
75 { ngx_string("Last-Modified"), 77 { ngx_string("Last-Modified"), 0, ngx_http_set_last_modified },
76 offsetof(ngx_http_headers_out_t, last_modified), 78
77 ngx_http_set_last_modified }, 79 { ngx_string("ETag"),
80 offsetof(ngx_http_headers_out_t, etag),
81 ngx_http_set_response_header },
78 82
79 { ngx_null_string, 0, NULL } 83 { ngx_null_string, 0, NULL }
80 }; 84 };
81 85
82 86
366 370
367 static ngx_int_t 371 static ngx_int_t
368 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv, 372 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv,
369 ngx_str_t *value) 373 ngx_str_t *value)
370 { 374 {
375 ngx_table_elt_t *h;
376
377 ngx_http_clear_last_modified(r);
378
379 if (value->len == 0) {
380 return NGX_OK;
381 }
382
383 r->headers_out.last_modified_time = ngx_http_parse_time(value->data,
384 value->len);
385
386 h = ngx_list_push(&r->headers_out.headers);
387 if (h == NULL) {
388 return NGX_ERROR;
389 }
390
391 r->headers_out.last_modified = h;
392
393 h->hash = 1;
394 h->key = hv->key;
395 h->value = *value;
396
397 return NGX_OK;
398 }
399
400
401 static ngx_int_t
402 ngx_http_set_response_header(ngx_http_request_t *r, ngx_http_header_val_t *hv,
403 ngx_str_t *value)
404 {
371 ngx_table_elt_t *h, **old; 405 ngx_table_elt_t *h, **old;
372 406
373 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); 407 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
374 408
375 r->headers_out.last_modified_time = -1; 409 if (*old) {
376 410 (*old)->hash = 0;
377 if (*old == NULL) { 411 *old = NULL;
378 412 }
379 if (value->len == 0) { 413
380 return NGX_OK; 414 if (value->len == 0) {
381 } 415 return NGX_OK;
382 416 }
383 h = ngx_list_push(&r->headers_out.headers); 417
384 if (h == NULL) { 418 h = ngx_list_push(&r->headers_out.headers);
385 return NGX_ERROR; 419 if (h == NULL) {
386 } 420 return NGX_ERROR;
387 421 }
388 *old = h; 422
389 423 *old = h;
390 } else {
391 h = *old;
392
393 if (value->len == 0) {
394 h->hash = 0;
395 return NGX_OK;
396 }
397 }
398 424
399 h->hash = 1; 425 h->hash = 1;
400 h->key = hv->key; 426 h->key = hv->key;
401 h->value = *value; 427 h->value = *value;
402 428