comparison src/http/modules/ngx_http_headers_filter_module.c @ 668:9fbf3ad94cbf NGINX_1_1_18

nginx 1.1.18 *) Change: keepalive connections are no longer disabled for Safari by default. *) Feature: the $connection_requests variable. *) Feature: $tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd and $tcpinfo_rcv_space variables. *) Feature: the "worker_cpu_affinity" directive now works on FreeBSD. *) Feature: the "xslt_param" and "xslt_string_param" directives. Thanks to Samuel Behan. *) Bugfix: in configure tests. Thanks to Piotr Sikora. *) Bugfix: in the ngx_http_xslt_filter_module. *) Bugfix: nginx could not be built on Debian GNU/Hurd.
author Igor Sysoev <http://sysoev.ru>
date Wed, 28 Mar 2012 00:00:00 +0400
parents f5b859b2f097
children 597573166f34
comparison
equal deleted inserted replaced
667:e0eabdb2bad1 668:9fbf3ad94cbf
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
384 h = ngx_list_push(&r->headers_out.headers); 383 h = ngx_list_push(&r->headers_out.headers);
385 if (h == NULL) { 384 if (h == NULL) {
386 return NGX_ERROR; 385 return NGX_ERROR;
387 } 386 }
387
388 *old = h;
388 389
389 } else { 390 } else {
390 h = *old; 391 h = *old;
391 392
392 if (value->len == 0) { 393 if (value->len == 0) {
393 h->hash = 0; 394 h->hash = 0;
394 return NGX_OK; 395 return NGX_OK;
395 } 396 }
396 } 397 }
397 398
398 h->hash = hv->hash; 399 h->hash = 1;
399 h->key = hv->key; 400 h->key = hv->key;
400 h->value = *value; 401 h->value = *value;
401 402
402 return NGX_OK; 403 return NGX_OK;
403 } 404 }
418 * 419 *
419 * conf->headers = NULL; 420 * conf->headers = NULL;
420 * conf->expires_time = 0; 421 * conf->expires_time = 0;
421 */ 422 */
422 423
423 conf->expires = NGX_CONF_UNSET_UINT; 424 conf->expires = NGX_HTTP_EXPIRES_UNSET;
424 425
425 return conf; 426 return conf;
426 } 427 }
427 428
428 429
430 ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child) 431 ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child)
431 { 432 {
432 ngx_http_headers_conf_t *prev = parent; 433 ngx_http_headers_conf_t *prev = parent;
433 ngx_http_headers_conf_t *conf = child; 434 ngx_http_headers_conf_t *conf = child;
434 435
435 if (conf->expires == NGX_CONF_UNSET_UINT) { 436 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) {
436 conf->expires = prev->expires; 437 conf->expires = prev->expires;
437 conf->expires_time = prev->expires_time; 438 conf->expires_time = prev->expires_time;
438 439
439 if (conf->expires == NGX_CONF_UNSET_UINT) { 440 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) {
440 conf->expires = NGX_HTTP_EXPIRES_OFF; 441 conf->expires = NGX_HTTP_EXPIRES_OFF;
441 } 442 }
442 } 443 }
443 444
444 if (conf->headers == NULL) { 445 if (conf->headers == NULL) {
465 ngx_http_headers_conf_t *hcf = conf; 466 ngx_http_headers_conf_t *hcf = conf;
466 467
467 ngx_uint_t minus, n; 468 ngx_uint_t minus, n;
468 ngx_str_t *value; 469 ngx_str_t *value;
469 470
470 if (hcf->expires != NGX_CONF_UNSET_UINT) { 471 if (hcf->expires != NGX_HTTP_EXPIRES_UNSET) {
471 return "is duplicate"; 472 return "is duplicate";
472 } 473 }
473 474
474 value = cf->args->elts; 475 value = cf->args->elts;
475 476
574 hv = ngx_array_push(hcf->headers); 575 hv = ngx_array_push(hcf->headers);
575 if (hv == NULL) { 576 if (hv == NULL) {
576 return NGX_CONF_ERROR; 577 return NGX_CONF_ERROR;
577 } 578 }
578 579
579 hv->hash = 1;
580 hv->key = value[1]; 580 hv->key = value[1];
581 hv->handler = ngx_http_add_header; 581 hv->handler = ngx_http_add_header;
582 hv->offset = 0; 582 hv->offset = 0;
583 583
584 set = ngx_http_set_headers; 584 set = ngx_http_set_headers;