comparison src/http/modules/ngx_http_headers_filter_module.c @ 4974:9d9ee85db35d

Slightly optimized code that handles special headers in "add_header".
author Ruslan Ermilov <ru@nginx.com>
date Wed, 19 Dec 2012 10:30:45 +0000
parents 1e2ac45ad25d
children 837d0a1bc31c
comparison
equal deleted inserted replaced
4973:44fcb9677c3f 4974:9d9ee85db35d
72 72
73 static ngx_http_set_header_t ngx_http_set_headers[] = { 73 static ngx_http_set_header_t ngx_http_set_headers[] = {
74 74
75 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control }, 75 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control },
76 76
77 { ngx_string("Last-Modified"), 0, ngx_http_set_last_modified }, 77 { ngx_string("Last-Modified"),
78 offsetof(ngx_http_headers_out_t, last_modified),
79 ngx_http_set_last_modified },
78 80
79 { ngx_string("ETag"), 81 { ngx_string("ETag"),
80 offsetof(ngx_http_headers_out_t, etag), 82 offsetof(ngx_http_headers_out_t, etag),
81 ngx_http_set_response_header }, 83 ngx_http_set_response_header },
82 84
370 372
371 static ngx_int_t 373 static ngx_int_t
372 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv, 374 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv,
373 ngx_str_t *value) 375 ngx_str_t *value)
374 { 376 {
375 ngx_table_elt_t *h; 377 if (ngx_http_set_response_header(r, hv, value) != NGX_OK) {
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; 378 return NGX_ERROR;
389 } 379 }
390 380
391 r->headers_out.last_modified = h; 381 r->headers_out.last_modified_time =
392 382 (value->len) ? ngx_http_parse_time(value->data, value->len) : -1;
393 h->hash = 1;
394 h->key = hv->key;
395 h->value = *value;
396 383
397 return NGX_OK; 384 return NGX_OK;
398 } 385 }
399 386
400 387
404 { 391 {
405 ngx_table_elt_t *h, **old; 392 ngx_table_elt_t *h, **old;
406 393
407 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); 394 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset);
408 395
396 if (value->len == 0) {
397 if (*old) {
398 (*old)->hash = 0;
399 *old = NULL;
400 }
401
402 return NGX_OK;
403 }
404
409 if (*old) { 405 if (*old) {
410 (*old)->hash = 0; 406 h = *old;
411 *old = NULL; 407
412 } 408 } else {
413 409 h = ngx_list_push(&r->headers_out.headers);
414 if (value->len == 0) { 410 if (h == NULL) {
415 return NGX_OK; 411 return NGX_ERROR;
416 } 412 }
417 413
418 h = ngx_list_push(&r->headers_out.headers); 414 *old = h;
419 if (h == NULL) { 415 }
420 return NGX_ERROR;
421 }
422
423 *old = h;
424 416
425 h->hash = 1; 417 h->hash = 1;
426 h->key = hv->key; 418 h->key = hv->key;
427 h->value = *value; 419 h->value = *value;
428 420