Mercurial > hg > nginx
comparison src/http/modules/ngx_http_headers_filter_module.c @ 7199:6ba68ad8b24c
Basic support of the Link response header.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 08 Feb 2018 09:54:18 +0300 |
parents | 8666da1ecf33 |
children | ef6a3a99a81a |
comparison
equal
deleted
inserted
replaced
7198:573f20116163 | 7199:6ba68ad8b24c |
---|---|
54 | 54 |
55 static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r, | 55 static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r, |
56 ngx_http_headers_conf_t *conf); | 56 ngx_http_headers_conf_t *conf); |
57 static ngx_int_t ngx_http_parse_expires(ngx_str_t *value, | 57 static ngx_int_t ngx_http_parse_expires(ngx_str_t *value, |
58 ngx_http_expires_t *expires, time_t *expires_time, char **err); | 58 ngx_http_expires_t *expires, time_t *expires_time, char **err); |
59 static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r, | 59 static ngx_int_t ngx_http_add_multi_header_lines(ngx_http_request_t *r, |
60 ngx_http_header_val_t *hv, ngx_str_t *value); | 60 ngx_http_header_val_t *hv, ngx_str_t *value); |
61 static ngx_int_t ngx_http_add_header(ngx_http_request_t *r, | 61 static ngx_int_t ngx_http_add_header(ngx_http_request_t *r, |
62 ngx_http_header_val_t *hv, ngx_str_t *value); | 62 ngx_http_header_val_t *hv, ngx_str_t *value); |
63 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r, | 63 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r, |
64 ngx_http_header_val_t *hv, ngx_str_t *value); | 64 ngx_http_header_val_t *hv, ngx_str_t *value); |
75 void *conf); | 75 void *conf); |
76 | 76 |
77 | 77 |
78 static ngx_http_set_header_t ngx_http_set_headers[] = { | 78 static ngx_http_set_header_t ngx_http_set_headers[] = { |
79 | 79 |
80 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control }, | 80 { ngx_string("Cache-Control"), |
81 offsetof(ngx_http_headers_out_t, cache_control), | |
82 ngx_http_add_multi_header_lines }, | |
83 | |
84 { ngx_string("Link"), | |
85 offsetof(ngx_http_headers_out_t, link), | |
86 ngx_http_add_multi_header_lines }, | |
81 | 87 |
82 { ngx_string("Last-Modified"), | 88 { ngx_string("Last-Modified"), |
83 offsetof(ngx_http_headers_out_t, last_modified), | 89 offsetof(ngx_http_headers_out_t, last_modified), |
84 ngx_http_set_last_modified }, | 90 ngx_http_set_last_modified }, |
85 | 91 |
553 return NGX_OK; | 559 return NGX_OK; |
554 } | 560 } |
555 | 561 |
556 | 562 |
557 static ngx_int_t | 563 static ngx_int_t |
558 ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv, | 564 ngx_http_add_multi_header_lines(ngx_http_request_t *r, |
559 ngx_str_t *value) | 565 ngx_http_header_val_t *hv, ngx_str_t *value) |
560 { | 566 { |
561 ngx_table_elt_t *cc, **ccp; | 567 ngx_array_t *pa; |
568 ngx_table_elt_t *h, **ph; | |
562 | 569 |
563 if (value->len == 0) { | 570 if (value->len == 0) { |
564 return NGX_OK; | 571 return NGX_OK; |
565 } | 572 } |
566 | 573 |
567 ccp = r->headers_out.cache_control.elts; | 574 pa = (ngx_array_t *) ((char *) &r->headers_out + hv->offset); |
568 | 575 |
569 if (ccp == NULL) { | 576 if (pa->elts == NULL) { |
570 | 577 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) |
571 if (ngx_array_init(&r->headers_out.cache_control, r->pool, | |
572 1, sizeof(ngx_table_elt_t *)) | |
573 != NGX_OK) | |
574 { | 578 { |
575 return NGX_ERROR; | 579 return NGX_ERROR; |
576 } | 580 } |
577 } | 581 } |
578 | 582 |
579 cc = ngx_list_push(&r->headers_out.headers); | 583 h = ngx_list_push(&r->headers_out.headers); |
580 if (cc == NULL) { | 584 if (h == NULL) { |
581 return NGX_ERROR; | 585 return NGX_ERROR; |
582 } | 586 } |
583 | 587 |
584 cc->hash = 1; | 588 h->hash = 1; |
585 ngx_str_set(&cc->key, "Cache-Control"); | 589 h->key = hv->key; |
586 cc->value = *value; | 590 h->value = *value; |
587 | 591 |
588 ccp = ngx_array_push(&r->headers_out.cache_control); | 592 ph = ngx_array_push(pa); |
589 if (ccp == NULL) { | 593 if (ph == NULL) { |
590 return NGX_ERROR; | 594 return NGX_ERROR; |
591 } | 595 } |
592 | 596 |
593 *ccp = cc; | 597 *ph = h; |
594 | 598 |
595 return NGX_OK; | 599 return NGX_OK; |
596 } | 600 } |
597 | 601 |
598 | 602 |