Mercurial > hg > nginx
comparison src/http/modules/ngx_http_headers_filter_module.c @ 4547:2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
- Removed "hash" element from ngx_http_header_val_t which was always 1.
- Replaced NGX_HTTP_EXPIRES_* with ngx_http_expires_t enum type.
- Added prototype for ngx_http_add_header()
- Simplified ngx_http_set_last_modified().
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 21 Mar 2012 06:19:11 +0000 |
parents | d11f86a16e3b |
children | 4c1e6cef1453 |
comparison
equal
deleted
inserted
replaced
4546:4988fa232629 | 4547:2577c27cbffd |
---|---|
23 } ngx_http_set_header_t; | 23 } ngx_http_set_header_t; |
24 | 24 |
25 | 25 |
26 struct ngx_http_header_val_s { | 26 struct ngx_http_header_val_s { |
27 ngx_http_complex_value_t value; | 27 ngx_http_complex_value_t value; |
28 ngx_uint_t hash; | |
29 ngx_str_t key; | 28 ngx_str_t key; |
30 ngx_http_set_header_pt handler; | 29 ngx_http_set_header_pt handler; |
31 ngx_uint_t offset; | 30 ngx_uint_t offset; |
32 }; | 31 }; |
33 | 32 |
34 | 33 |
35 #define NGX_HTTP_EXPIRES_OFF 0 | 34 typedef enum { |
36 #define NGX_HTTP_EXPIRES_EPOCH 1 | 35 NGX_HTTP_EXPIRES_OFF, |
37 #define NGX_HTTP_EXPIRES_MAX 2 | 36 NGX_HTTP_EXPIRES_EPOCH, |
38 #define NGX_HTTP_EXPIRES_ACCESS 3 | 37 NGX_HTTP_EXPIRES_MAX, |
39 #define NGX_HTTP_EXPIRES_MODIFIED 4 | 38 NGX_HTTP_EXPIRES_ACCESS, |
40 #define NGX_HTTP_EXPIRES_DAILY 5 | 39 NGX_HTTP_EXPIRES_MODIFIED, |
40 NGX_HTTP_EXPIRES_DAILY, | |
41 NGX_HTTP_EXPIRES_UNSET | |
42 } ngx_http_expires_t; | |
41 | 43 |
42 | 44 |
43 typedef struct { | 45 typedef struct { |
44 ngx_uint_t expires; | 46 ngx_http_expires_t expires; |
45 time_t expires_time; | 47 time_t expires_time; |
46 ngx_array_t *headers; | 48 ngx_array_t *headers; |
47 } ngx_http_headers_conf_t; | 49 } ngx_http_headers_conf_t; |
48 | 50 |
49 | 51 |
50 static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r, | 52 static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r, |
51 ngx_http_headers_conf_t *conf); | 53 ngx_http_headers_conf_t *conf); |
52 static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r, | 54 static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r, |
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, | |
53 ngx_http_header_val_t *hv, ngx_str_t *value); | 57 ngx_http_header_val_t *hv, ngx_str_t *value); |
54 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, |
55 ngx_http_header_val_t *hv, ngx_str_t *value); | 59 ngx_http_header_val_t *hv, ngx_str_t *value); |
56 | 60 |
57 static void *ngx_http_headers_create_conf(ngx_conf_t *cf); | 61 static void *ngx_http_headers_create_conf(ngx_conf_t *cf); |
311 h = ngx_list_push(&r->headers_out.headers); | 315 h = ngx_list_push(&r->headers_out.headers); |
312 if (h == NULL) { | 316 if (h == NULL) { |
313 return NGX_ERROR; | 317 return NGX_ERROR; |
314 } | 318 } |
315 | 319 |
316 h->hash = hv->hash; | 320 h->hash = 1; |
317 h->key = hv->key; | 321 h->key = hv->key; |
318 h->value = *value; | 322 h->value = *value; |
319 } | 323 } |
320 | 324 |
321 return NGX_OK; | 325 return NGX_OK; |
364 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv, | 368 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv, |
365 ngx_str_t *value) | 369 ngx_str_t *value) |
366 { | 370 { |
367 ngx_table_elt_t *h, **old; | 371 ngx_table_elt_t *h, **old; |
368 | 372 |
369 if (hv->offset) { | 373 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); |
370 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); | |
371 | |
372 } else { | |
373 old = NULL; | |
374 } | |
375 | 374 |
376 r->headers_out.last_modified_time = -1; | 375 r->headers_out.last_modified_time = -1; |
377 | 376 |
378 if (old == NULL || *old == NULL) { | 377 if (*old == NULL) { |
379 | 378 |
380 if (value->len == 0) { | 379 if (value->len == 0) { |
381 return NGX_OK; | 380 return NGX_OK; |
382 } | 381 } |
383 | 382 |
393 h->hash = 0; | 392 h->hash = 0; |
394 return NGX_OK; | 393 return NGX_OK; |
395 } | 394 } |
396 } | 395 } |
397 | 396 |
398 h->hash = hv->hash; | 397 h->hash = 1; |
399 h->key = hv->key; | 398 h->key = hv->key; |
400 h->value = *value; | 399 h->value = *value; |
401 | 400 |
402 return NGX_OK; | 401 return NGX_OK; |
403 } | 402 } |
418 * | 417 * |
419 * conf->headers = NULL; | 418 * conf->headers = NULL; |
420 * conf->expires_time = 0; | 419 * conf->expires_time = 0; |
421 */ | 420 */ |
422 | 421 |
423 conf->expires = NGX_CONF_UNSET_UINT; | 422 conf->expires = NGX_HTTP_EXPIRES_UNSET; |
424 | 423 |
425 return conf; | 424 return conf; |
426 } | 425 } |
427 | 426 |
428 | 427 |
430 ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child) | 429 ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
431 { | 430 { |
432 ngx_http_headers_conf_t *prev = parent; | 431 ngx_http_headers_conf_t *prev = parent; |
433 ngx_http_headers_conf_t *conf = child; | 432 ngx_http_headers_conf_t *conf = child; |
434 | 433 |
435 if (conf->expires == NGX_CONF_UNSET_UINT) { | 434 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
436 conf->expires = prev->expires; | 435 conf->expires = prev->expires; |
437 conf->expires_time = prev->expires_time; | 436 conf->expires_time = prev->expires_time; |
438 | 437 |
439 if (conf->expires == NGX_CONF_UNSET_UINT) { | 438 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
440 conf->expires = NGX_HTTP_EXPIRES_OFF; | 439 conf->expires = NGX_HTTP_EXPIRES_OFF; |
441 } | 440 } |
442 } | 441 } |
443 | 442 |
444 if (conf->headers == NULL) { | 443 if (conf->headers == NULL) { |
465 ngx_http_headers_conf_t *hcf = conf; | 464 ngx_http_headers_conf_t *hcf = conf; |
466 | 465 |
467 ngx_uint_t minus, n; | 466 ngx_uint_t minus, n; |
468 ngx_str_t *value; | 467 ngx_str_t *value; |
469 | 468 |
470 if (hcf->expires != NGX_CONF_UNSET_UINT) { | 469 if (hcf->expires != NGX_HTTP_EXPIRES_UNSET) { |
471 return "is duplicate"; | 470 return "is duplicate"; |
472 } | 471 } |
473 | 472 |
474 value = cf->args->elts; | 473 value = cf->args->elts; |
475 | 474 |
574 hv = ngx_array_push(hcf->headers); | 573 hv = ngx_array_push(hcf->headers); |
575 if (hv == NULL) { | 574 if (hv == NULL) { |
576 return NGX_CONF_ERROR; | 575 return NGX_CONF_ERROR; |
577 } | 576 } |
578 | 577 |
579 hv->hash = 1; | |
580 hv->key = value[1]; | 578 hv->key = value[1]; |
581 hv->handler = ngx_http_add_header; | 579 hv->handler = ngx_http_add_header; |
582 hv->offset = 0; | 580 hv->offset = 0; |
583 | 581 |
584 set = ngx_http_set_headers; | 582 set = ngx_http_set_headers; |