comparison src/http/modules/ngx_http_headers_filter_module.c @ 4747:1e2ac45ad25d

Entity tags: handling in add_header. Notably this allows to clear ETag if one want to for some reason.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 07 Jul 2012 21:24:01 +0000
parents 3cb5cf1e1439
children 9d9ee85db35d
comparison
equal deleted inserted replaced
4746:4a18bf1833a9 4747:1e2ac45ad25d
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);
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"), 0, ngx_http_set_last_modified }, 77 { ngx_string("Last-Modified"), 0, ngx_http_set_last_modified },
78
79 { ngx_string("ETag"),
80 offsetof(ngx_http_headers_out_t, etag),
81 ngx_http_set_response_header },
76 82
77 { ngx_null_string, 0, NULL } 83 { ngx_null_string, 0, NULL }
78 }; 84 };
79 85
80 86
390 396
391 return NGX_OK; 397 return NGX_OK;
392 } 398 }
393 399
394 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 {
405 ngx_table_elt_t *h, **old;
406
407 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
408
409 if (*old) {
410 (*old)->hash = 0;
411 *old = NULL;
412 }
413
414 if (value->len == 0) {
415 return NGX_OK;
416 }
417
418 h = ngx_list_push(&r->headers_out.headers);
419 if (h == NULL) {
420 return NGX_ERROR;
421 }
422
423 *old = h;
424
425 h->hash = 1;
426 h->key = hv->key;
427 h->value = *value;
428
429 return NGX_OK;
430 }
431
432
395 static void * 433 static void *
396 ngx_http_headers_create_conf(ngx_conf_t *cf) 434 ngx_http_headers_create_conf(ngx_conf_t *cf)
397 { 435 {
398 ngx_http_headers_conf_t *conf; 436 ngx_http_headers_conf_t *conf;
399 437