Mercurial > hg > nginx
annotate src/http/modules/ngx_http_headers_filter_module.c @ 8535:eb5aa85294e9 quic
QUIC: discard unrecognized long packes.
While there, updated comment about discarded packets.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 02 Sep 2020 09:54:15 +0300 |
parents | 6ba68ad8b24c |
children | ef6a3a99a81a |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
6 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
13 typedef struct ngx_http_header_val_s ngx_http_header_val_t; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
14 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
15 typedef ngx_int_t (*ngx_http_set_header_pt)(ngx_http_request_t *r, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
16 ngx_http_header_val_t *hv, ngx_str_t *value); |
625 | 17 |
18 | |
19 typedef struct { | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
20 ngx_str_t name; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
21 ngx_uint_t offset; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
22 ngx_http_set_header_pt handler; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
23 } ngx_http_set_header_t; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
24 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
25 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
26 struct ngx_http_header_val_s { |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
27 ngx_http_complex_value_t value; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
28 ngx_str_t key; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
29 ngx_http_set_header_pt handler; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
30 ngx_uint_t offset; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
31 ngx_uint_t always; /* unsigned always:1 */ |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
32 }; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
33 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
34 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
35 typedef enum { |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
36 NGX_HTTP_EXPIRES_OFF, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
37 NGX_HTTP_EXPIRES_EPOCH, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
38 NGX_HTTP_EXPIRES_MAX, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
39 NGX_HTTP_EXPIRES_ACCESS, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
40 NGX_HTTP_EXPIRES_MODIFIED, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
41 NGX_HTTP_EXPIRES_DAILY, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
42 NGX_HTTP_EXPIRES_UNSET |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
43 } ngx_http_expires_t; |
2013 | 44 |
45 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
46 typedef struct { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
47 ngx_http_expires_t expires; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
48 time_t expires_time; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
49 ngx_http_complex_value_t *expires_value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
50 ngx_array_t *headers; |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
51 ngx_array_t *trailers; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 } ngx_http_headers_conf_t; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
55 static ngx_int_t ngx_http_set_expires(ngx_http_request_t *r, |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
56 ngx_http_headers_conf_t *conf); |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
57 static ngx_int_t ngx_http_parse_expires(ngx_str_t *value, |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
58 ngx_http_expires_t *expires, time_t *expires_time, char **err); |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
59 static ngx_int_t ngx_http_add_multi_header_lines(ngx_http_request_t *r, |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
60 ngx_http_header_val_t *hv, ngx_str_t *value); |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
61 static ngx_int_t ngx_http_add_header(ngx_http_request_t *r, |
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
62 ngx_http_header_val_t *hv, ngx_str_t *value); |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
63 static ngx_int_t ngx_http_set_last_modified(ngx_http_request_t *r, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
64 ngx_http_header_val_t *hv, ngx_str_t *value); |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
65 static ngx_int_t ngx_http_set_response_header(ngx_http_request_t *r, |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
66 ngx_http_header_val_t *hv, ngx_str_t *value); |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
67 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
68 static void *ngx_http_headers_create_conf(ngx_conf_t *cf); |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf, |
573 | 70 void *parent, void *child); |
681 | 71 static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf); |
501 | 72 static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, |
73 void *conf); | |
573 | 74 static char *ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, |
75 void *conf); | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
77 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
78 static ngx_http_set_header_t ngx_http_set_headers[] = { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
79 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
80 { ngx_string("Cache-Control"), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
81 offsetof(ngx_http_headers_out_t, cache_control), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
82 ngx_http_add_multi_header_lines }, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
83 |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
84 { ngx_string("Link"), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
85 offsetof(ngx_http_headers_out_t, link), |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
86 ngx_http_add_multi_header_lines }, |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
87 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
88 { ngx_string("Last-Modified"), |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
89 offsetof(ngx_http_headers_out_t, last_modified), |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
90 ngx_http_set_last_modified }, |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
91 |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
92 { ngx_string("ETag"), |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
93 offsetof(ngx_http_headers_out_t, etag), |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
94 ngx_http_set_response_header }, |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
95 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
96 { ngx_null_string, 0, NULL } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
97 }; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
98 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
99 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 static ngx_command_t ngx_http_headers_filter_commands[] = { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 { ngx_string("expires"), |
573 | 103 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
2013 | 104 |NGX_CONF_TAKE12, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 ngx_http_headers_expires, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 NGX_HTTP_LOC_CONF_OFFSET, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 0, |
7017
057ec63be834
Headers filter: style.
Piotr Sikora <piotrsikora@google.com>
parents:
6986
diff
changeset
|
108 NULL }, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
573 | 110 { ngx_string("add_header"), |
111 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF | |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
112 |NGX_CONF_TAKE23, |
573 | 113 ngx_http_headers_add, |
114 NGX_HTTP_LOC_CONF_OFFSET, | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
115 offsetof(ngx_http_headers_conf_t, headers), |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
116 NULL }, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
117 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
118 { ngx_string("add_trailer"), |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
119 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
120 |NGX_CONF_TAKE23, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
121 ngx_http_headers_add, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
122 NGX_HTTP_LOC_CONF_OFFSET, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
123 offsetof(ngx_http_headers_conf_t, trailers), |
7017
057ec63be834
Headers filter: style.
Piotr Sikora <piotrsikora@google.com>
parents:
6986
diff
changeset
|
124 NULL }, |
573 | 125 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 ngx_null_command |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
128 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 static ngx_http_module_t ngx_http_headers_filter_module_ctx = { |
509 | 131 NULL, /* preconfiguration */ |
681 | 132 ngx_http_headers_filter_init, /* postconfiguration */ |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 NULL, /* create main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 NULL, /* init main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 NULL, /* create server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 NULL, /* merge server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 ngx_http_headers_create_conf, /* create location configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 ngx_http_headers_merge_conf /* merge location configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
143 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
145 ngx_module_t ngx_http_headers_filter_module = { |
509 | 146 NGX_MODULE_V1, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 &ngx_http_headers_filter_module_ctx, /* module context */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 ngx_http_headers_filter_commands, /* module directives */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 NGX_HTTP_MODULE, /* module type */ |
541 | 150 NULL, /* init master */ |
681 | 151 NULL, /* init module */ |
541 | 152 NULL, /* init process */ |
153 NULL, /* init thread */ | |
154 NULL, /* exit thread */ | |
155 NULL, /* exit process */ | |
156 NULL, /* exit master */ | |
157 NGX_MODULE_V1_PADDING | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
162 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
501 | 165 static ngx_int_t |
166 ngx_http_headers_filter(ngx_http_request_t *r) | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 { |
1364 | 168 ngx_str_t value; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
169 ngx_uint_t i, safe_status; |
625 | 170 ngx_http_header_val_t *h; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 ngx_http_headers_conf_t *conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
173 if (r != r->main) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
174 return ngx_http_next_header_filter(r); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
175 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
176 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
177 conf = ngx_http_get_module_loc_conf(r, ngx_http_headers_filter_module); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
178 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
179 if (conf->expires == NGX_HTTP_EXPIRES_OFF |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
180 && conf->headers == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
181 && conf->trailers == NULL) |
543 | 182 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 return ngx_http_next_header_filter(r); |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
186 switch (r->headers_out.status) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
187 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
188 case NGX_HTTP_OK: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
189 case NGX_HTTP_CREATED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
190 case NGX_HTTP_NO_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
191 case NGX_HTTP_PARTIAL_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
192 case NGX_HTTP_MOVED_PERMANENTLY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
193 case NGX_HTTP_MOVED_TEMPORARILY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
194 case NGX_HTTP_SEE_OTHER: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
195 case NGX_HTTP_NOT_MODIFIED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
196 case NGX_HTTP_TEMPORARY_REDIRECT: |
6977
be5cfa918bfc
Added support for the "308 Permanent Redirect" (ticket #877).
Simon Leblanc <contact@leblanc-simon.eu>
parents:
6405
diff
changeset
|
197 case NGX_HTTP_PERMANENT_REDIRECT: |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
198 safe_status = 1; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
199 break; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
200 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
201 default: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
202 safe_status = 0; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
203 break; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
204 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
205 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
206 if (conf->expires != NGX_HTTP_EXPIRES_OFF && safe_status) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
207 if (ngx_http_set_expires(r, conf) != NGX_OK) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
208 return NGX_ERROR; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
573 | 212 if (conf->headers) { |
213 h = conf->headers->elts; | |
214 for (i = 0; i < conf->headers->nelts; i++) { | |
625 | 215 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
216 if (!safe_status && !h[i].always) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
217 continue; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
218 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
219 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
220 if (ngx_http_complex_value(r, &h[i].value, &value) != NGX_OK) { |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
221 return NGX_ERROR; |
625 | 222 } |
223 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
224 if (h[i].handler(r, &h[i], &value) != NGX_OK) { |
625 | 225 return NGX_ERROR; |
226 } | |
573 | 227 } |
228 } | |
229 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
230 if (conf->trailers) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
231 h = conf->trailers->elts; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
232 for (i = 0; i < conf->trailers->nelts; i++) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
233 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
234 if (!safe_status && !h[i].always) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
235 continue; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
236 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
237 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
238 r->expect_trailers = 1; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
239 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
240 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
241 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
242 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
243 return ngx_http_next_header_filter(r); |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
244 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
245 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
246 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
247 static ngx_int_t |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
248 ngx_http_trailers_filter(ngx_http_request_t *r, ngx_chain_t *in) |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
249 { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
250 ngx_str_t value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
251 ngx_uint_t i, safe_status; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
252 ngx_chain_t *cl; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
253 ngx_table_elt_t *t; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
254 ngx_http_header_val_t *h; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
255 ngx_http_headers_conf_t *conf; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
256 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
257 conf = ngx_http_get_module_loc_conf(r, ngx_http_headers_filter_module); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
258 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
259 if (in == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
260 || conf->trailers == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
261 || !r->expect_trailers |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
262 || r->header_only) |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
263 { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
264 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
265 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
266 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
267 for (cl = in; cl; cl = cl->next) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
268 if (cl->buf->last_buf) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
269 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
270 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
271 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
272 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
273 if (cl == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
274 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
275 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
276 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
277 switch (r->headers_out.status) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
278 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
279 case NGX_HTTP_OK: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
280 case NGX_HTTP_CREATED: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
281 case NGX_HTTP_NO_CONTENT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
282 case NGX_HTTP_PARTIAL_CONTENT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
283 case NGX_HTTP_MOVED_PERMANENTLY: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
284 case NGX_HTTP_MOVED_TEMPORARILY: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
285 case NGX_HTTP_SEE_OTHER: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
286 case NGX_HTTP_NOT_MODIFIED: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
287 case NGX_HTTP_TEMPORARY_REDIRECT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
288 case NGX_HTTP_PERMANENT_REDIRECT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
289 safe_status = 1; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
290 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
291 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
292 default: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
293 safe_status = 0; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
294 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
295 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
296 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
297 h = conf->trailers->elts; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
298 for (i = 0; i < conf->trailers->nelts; i++) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
299 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
300 if (!safe_status && !h[i].always) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
301 continue; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
302 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
303 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
304 if (ngx_http_complex_value(r, &h[i].value, &value) != NGX_OK) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
305 return NGX_ERROR; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
306 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
307 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
308 if (value.len) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
309 t = ngx_list_push(&r->headers_out.trailers); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
310 if (t == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
311 return NGX_ERROR; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
312 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
313 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
314 t->key = h[i].key; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
315 t->value = value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
316 t->hash = 1; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
317 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
318 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
319 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
320 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
321 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
322 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
323 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
324 static ngx_int_t |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
325 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
326 { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
327 char *err; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
328 size_t len; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
329 time_t now, expires_time, max_age; |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
330 ngx_str_t value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
331 ngx_int_t rc; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
332 ngx_uint_t i; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
333 ngx_table_elt_t *e, *cc, **ccp; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
334 ngx_http_expires_t expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
335 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
336 expires = conf->expires; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
337 expires_time = conf->expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
338 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
339 if (conf->expires_value != NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
340 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
341 if (ngx_http_complex_value(r, conf->expires_value, &value) != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
342 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
343 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
344 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
345 rc = ngx_http_parse_expires(&value, &expires, &expires_time, &err); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
346 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
347 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
348 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
349 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
350 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
351 if (expires == NGX_HTTP_EXPIRES_OFF) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
352 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
353 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
354 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
355 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
356 e = r->headers_out.expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
357 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
358 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
359 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
360 e = ngx_list_push(&r->headers_out.headers); |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
361 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
362 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
363 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
364 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
365 r->headers_out.expires = e; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
366 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
367 e->hash = 1; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
368 ngx_str_set(&e->key, "Expires"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
369 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
370 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
371 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
372 e->value.len = len - 1; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
373 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
374 ccp = r->headers_out.cache_control.elts; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
375 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
376 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
377 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
378 if (ngx_array_init(&r->headers_out.cache_control, r->pool, |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
379 1, sizeof(ngx_table_elt_t *)) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
380 != NGX_OK) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
381 { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
382 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
383 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
384 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
385 cc = ngx_list_push(&r->headers_out.headers); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
386 if (cc == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
387 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
388 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
389 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
390 cc->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
391 ngx_str_set(&cc->key, "Cache-Control"); |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
392 |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
393 ccp = ngx_array_push(&r->headers_out.cache_control); |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
394 if (ccp == NULL) { |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
395 return NGX_ERROR; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
396 } |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
397 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
398 *ccp = cc; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
399 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
400 } else { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
401 for (i = 1; i < r->headers_out.cache_control.nelts; i++) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
402 ccp[i]->hash = 0; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
403 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
404 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
405 cc = ccp[0]; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
406 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
407 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
408 if (expires == NGX_HTTP_EXPIRES_EPOCH) { |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
409 e->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
410 ngx_str_set(&cc->value, "no-cache"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
411 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
412 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
413 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
414 if (expires == NGX_HTTP_EXPIRES_MAX) { |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
415 e->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT"; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
416 /* 10 years */ |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
417 ngx_str_set(&cc->value, "max-age=315360000"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
418 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
419 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
420 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
421 e->value.data = ngx_pnalloc(r->pool, len); |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
422 if (e->value.data == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
423 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
424 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
425 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
426 if (expires_time == 0 && expires != NGX_HTTP_EXPIRES_DAILY) { |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
427 ngx_memcpy(e->value.data, ngx_cached_http_time.data, |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
428 ngx_cached_http_time.len + 1); |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
429 ngx_str_set(&cc->value, "max-age=0"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
430 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
431 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
432 |
2163 | 433 now = ngx_time(); |
434 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
435 if (expires == NGX_HTTP_EXPIRES_DAILY) { |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
436 expires_time = ngx_next_time(expires_time); |
4217
ebec73b935d3
Fixed "expires @time" with unknown last modified time (ticket #32).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4216
diff
changeset
|
437 max_age = expires_time - now; |
ebec73b935d3
Fixed "expires @time" with unknown last modified time (ticket #32).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4216
diff
changeset
|
438 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
439 } else if (expires == NGX_HTTP_EXPIRES_ACCESS |
4217
ebec73b935d3
Fixed "expires @time" with unknown last modified time (ticket #32).
Maxim Dounin <mdounin@mdounin.ru>
parents:
4216
diff
changeset
|
440 || r->headers_out.last_modified_time == -1) |
2013 | 441 { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
442 max_age = expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
443 expires_time += now; |
2163 | 444 |
2013 | 445 } else { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
446 expires_time += r->headers_out.last_modified_time; |
2163 | 447 max_age = expires_time - now; |
2013 | 448 } |
449 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
450 ngx_http_time(e->value.data, expires_time); |
2013 | 451 |
3405
6cc74c87c656
fix negative time in "Cache-Control" if "expires modified" sets time in the past
Igor Sysoev <igor@sysoev.ru>
parents:
2912
diff
changeset
|
452 if (conf->expires_time < 0 || max_age < 0) { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
453 ngx_str_set(&cc->value, "no-cache"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
454 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
455 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
456 |
2049 | 457 cc->value.data = ngx_pnalloc(r->pool, |
458 sizeof("max-age=") + NGX_TIME_T_LEN + 1); | |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
459 if (cc->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
460 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
461 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
462 |
2163 | 463 cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", max_age) |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
464 - cc->value.data; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
465 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
466 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
467 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
468 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
469 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
470 static ngx_int_t |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
471 ngx_http_parse_expires(ngx_str_t *value, ngx_http_expires_t *expires, |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
472 time_t *expires_time, char **err) |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
473 { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
474 ngx_uint_t minus; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
475 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
476 if (*expires != NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
477 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
478 if (value->len == 5 && ngx_strncmp(value->data, "epoch", 5) == 0) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
479 *expires = NGX_HTTP_EXPIRES_EPOCH; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
480 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
481 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
482 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
483 if (value->len == 3 && ngx_strncmp(value->data, "max", 3) == 0) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
484 *expires = NGX_HTTP_EXPIRES_MAX; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
485 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
486 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
487 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
488 if (value->len == 3 && ngx_strncmp(value->data, "off", 3) == 0) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
489 *expires = NGX_HTTP_EXPIRES_OFF; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
490 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
491 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
492 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
493 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
494 if (value->len && value->data[0] == '@') { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
495 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
496 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
497 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
498 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
499 if (*expires == NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
500 *err = "daily time cannot be used with \"modified\" parameter"; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
501 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
502 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
503 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
504 *expires = NGX_HTTP_EXPIRES_DAILY; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
505 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
506 } else if (value->len && value->data[0] == '+') { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
507 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
508 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
509 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
510 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
511 } else if (value->len && value->data[0] == '-') { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
512 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
513 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
514 minus = 1; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
515 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
516 } else { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
517 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
518 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
519 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
520 *expires_time = ngx_parse_time(value, 1); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
521 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
522 if (*expires_time == (time_t) NGX_ERROR) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
523 *err = "invalid value"; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
524 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
525 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
526 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
527 if (*expires == NGX_HTTP_EXPIRES_DAILY |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
528 && *expires_time > 24 * 60 * 60) |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
529 { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
530 *err = "daily time value must be less than 24 hours"; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
531 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
532 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
533 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
534 if (minus) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
535 *expires_time = - *expires_time; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
536 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
537 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
538 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
539 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
540 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
541 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
542 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
543 ngx_http_add_header(ngx_http_request_t *r, ngx_http_header_val_t *hv, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
544 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
545 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
546 ngx_table_elt_t *h; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
547 |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
548 if (value->len) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
549 h = ngx_list_push(&r->headers_out.headers); |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
550 if (h == NULL) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
551 return NGX_ERROR; |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
552 } |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
553 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
554 h->hash = 1; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
555 h->key = hv->key; |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
556 h->value = *value; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
557 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
558 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
559 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
560 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
561 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
562 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
563 static ngx_int_t |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
564 ngx_http_add_multi_header_lines(ngx_http_request_t *r, |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
565 ngx_http_header_val_t *hv, ngx_str_t *value) |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
566 { |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
567 ngx_array_t *pa; |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
568 ngx_table_elt_t *h, **ph; |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
569 |
5427
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
570 if (value->len == 0) { |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
571 return NGX_OK; |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
572 } |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
573 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
574 pa = (ngx_array_t *) ((char *) &r->headers_out + hv->offset); |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
575 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
576 if (pa->elts == NULL) { |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
577 if (ngx_array_init(pa, r->pool, 1, sizeof(ngx_table_elt_t *)) != NGX_OK) |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
578 { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
579 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
580 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
581 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
582 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
583 h = ngx_list_push(&r->headers_out.headers); |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
584 if (h == NULL) { |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
585 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
586 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
587 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
588 h->hash = 1; |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
589 h->key = hv->key; |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
590 h->value = *value; |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
591 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
592 ph = ngx_array_push(pa); |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
593 if (ph == NULL) { |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
594 return NGX_ERROR; |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
595 } |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
596 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
597 *ph = h; |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
598 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
599 return NGX_OK; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
600 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
601 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
602 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
603 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
604 ngx_http_set_last_modified(ngx_http_request_t *r, ngx_http_header_val_t *hv, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
605 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
606 { |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
607 if (ngx_http_set_response_header(r, hv, value) != NGX_OK) { |
4742
3cb5cf1e1439
Added Last-Modified parsing in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4548
diff
changeset
|
608 return NGX_ERROR; |
3cb5cf1e1439
Added Last-Modified parsing in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4548
diff
changeset
|
609 } |
1655 | 610 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
611 r->headers_out.last_modified_time = |
6180
8b6fa4842133
Moved ngx_http_parse_time() to core, renamed accordingly.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6062
diff
changeset
|
612 (value->len) ? ngx_parse_http_time(value->data, value->len) : -1; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
613 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
614 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
615 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
616 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
617 |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
618 static ngx_int_t |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
619 ngx_http_set_response_header(ngx_http_request_t *r, ngx_http_header_val_t *hv, |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
620 ngx_str_t *value) |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
621 { |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
622 ngx_table_elt_t *h, **old; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
623 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
624 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
625 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
626 if (value->len == 0) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
627 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
628 (*old)->hash = 0; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
629 *old = NULL; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
630 } |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
631 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
632 return NGX_OK; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
633 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
634 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
635 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
636 h = *old; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
637 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
638 } else { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
639 h = ngx_list_push(&r->headers_out.headers); |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
640 if (h == NULL) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
641 return NGX_ERROR; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
642 } |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
643 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
644 *old = h; |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
645 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
646 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
647 h->hash = 1; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
648 h->key = hv->key; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
649 h->value = *value; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
650 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
651 return NGX_OK; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
652 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
653 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
654 |
501 | 655 static void * |
656 ngx_http_headers_create_conf(ngx_conf_t *cf) | |
577 | 657 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
658 ngx_http_headers_conf_t *conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
659 |
573 | 660 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t)); |
501 | 661 if (conf == NULL) { |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2605
diff
changeset
|
662 return NULL; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
663 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
664 |
573 | 665 /* |
666 * set by ngx_pcalloc(): | |
667 * | |
668 * conf->headers = NULL; | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
669 * conf->trailers = NULL; |
2013 | 670 * conf->expires_time = 0; |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
671 * conf->expires_value = NULL; |
573 | 672 */ |
673 | |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
674 conf->expires = NGX_HTTP_EXPIRES_UNSET; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
675 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
676 return conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
677 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
678 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
679 |
501 | 680 static char * |
681 ngx_http_headers_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
682 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
683 ngx_http_headers_conf_t *prev = parent; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
684 ngx_http_headers_conf_t *conf = child; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
685 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
686 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 687 conf->expires = prev->expires; |
688 conf->expires_time = prev->expires_time; | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
689 conf->expires_value = prev->expires_value; |
2013 | 690 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
691 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 692 conf->expires = NGX_HTTP_EXPIRES_OFF; |
693 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
694 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
695 |
573 | 696 if (conf->headers == NULL) { |
697 conf->headers = prev->headers; | |
698 } | |
699 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
700 if (conf->trailers == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
701 conf->trailers = prev->trailers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
702 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
703 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
704 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
705 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
706 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
707 |
681 | 708 static ngx_int_t |
709 ngx_http_headers_filter_init(ngx_conf_t *cf) | |
710 { | |
711 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
712 ngx_http_top_header_filter = ngx_http_headers_filter; | |
713 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
714 ngx_http_next_body_filter = ngx_http_top_body_filter; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
715 ngx_http_top_body_filter = ngx_http_trailers_filter; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
716 |
681 | 717 return NGX_OK; |
718 } | |
719 | |
720 | |
501 | 721 static char * |
722 ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
723 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
724 ngx_http_headers_conf_t *hcf = conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
725 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
726 char *err; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
727 ngx_str_t *value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
728 ngx_int_t rc; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
729 ngx_uint_t n; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
730 ngx_http_complex_value_t cv; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
731 ngx_http_compile_complex_value_t ccv; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
732 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
733 if (hcf->expires != NGX_HTTP_EXPIRES_UNSET) { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
734 return "is duplicate"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
735 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
736 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
737 value = cf->args->elts; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
738 |
2013 | 739 if (cf->args->nelts == 2) { |
740 | |
741 hcf->expires = NGX_HTTP_EXPIRES_ACCESS; | |
742 | |
743 n = 1; | |
744 | |
745 } else { /* cf->args->nelts == 3 */ | |
746 | |
747 if (ngx_strcmp(value[1].data, "modified") != 0) { | |
748 return "invalid value"; | |
749 } | |
750 | |
751 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; | |
752 | |
753 n = 2; | |
729 | 754 } |
755 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
756 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
757 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
758 ccv.cf = cf; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
759 ccv.value = &value[n]; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
760 ccv.complex_value = &cv; |
2163 | 761 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
762 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
763 return NGX_CONF_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
764 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
765 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
766 if (cv.lengths != NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
767 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
768 hcf->expires_value = ngx_palloc(cf->pool, |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
769 sizeof(ngx_http_complex_value_t)); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
770 if (hcf->expires_value == NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
771 return NGX_CONF_ERROR; |
2163 | 772 } |
773 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
774 *hcf->expires_value = cv; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
775 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
776 return NGX_CONF_OK; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
777 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
778 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
779 rc = ngx_http_parse_expires(&value[n], &hcf->expires, &hcf->expires_time, |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
780 &err); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
781 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
782 return err; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
783 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
784 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
785 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
786 } |
573 | 787 |
788 | |
789 static char * | |
790 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
791 { | |
792 ngx_http_headers_conf_t *hcf = conf; | |
793 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
794 ngx_str_t *value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
795 ngx_uint_t i; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
796 ngx_array_t **headers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
797 ngx_http_header_val_t *hv; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
798 ngx_http_set_header_t *set; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
799 ngx_http_compile_complex_value_t ccv; |
573 | 800 |
801 value = cf->args->elts; | |
802 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
803 headers = (ngx_array_t **) ((char *) hcf + cmd->offset); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
804 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
805 if (*headers == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
806 *headers = ngx_array_create(cf->pool, 1, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
807 sizeof(ngx_http_header_val_t)); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
808 if (*headers == NULL) { |
573 | 809 return NGX_CONF_ERROR; |
810 } | |
811 } | |
812 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
813 hv = ngx_array_push(*headers); |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
814 if (hv == NULL) { |
573 | 815 return NGX_CONF_ERROR; |
816 } | |
817 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
818 hv->key = value[1]; |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
819 hv->handler = NULL; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
820 hv->offset = 0; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
821 hv->always = 0; |
625 | 822 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
823 if (headers == &hcf->headers) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
824 hv->handler = ngx_http_add_header; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
825 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
826 set = ngx_http_set_headers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
827 for (i = 0; set[i].name.len; i++) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
828 if (ngx_strcasecmp(value[1].data, set[i].name.data) != 0) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
829 continue; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
830 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
831 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
832 hv->offset = set[i].offset; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
833 hv->handler = set[i].handler; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
834 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
835 break; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
836 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
837 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
838 |
2605
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
839 if (value[2].len == 0) { |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
840 ngx_memzero(&hv->value, sizeof(ngx_http_complex_value_t)); |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
841 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
842 } else { |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
843 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
625 | 844 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
845 ccv.cf = cf; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
846 ccv.value = &value[2]; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
847 ccv.complex_value = &hv->value; |
625 | 848 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
849 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
850 return NGX_CONF_ERROR; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
851 } |
625 | 852 } |
573 | 853 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
854 if (cf->args->nelts == 3) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
855 return NGX_CONF_OK; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
856 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
857 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
858 if (ngx_strcmp(value[3].data, "always") != 0) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
859 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
860 "invalid parameter \"%V\"", &value[3]); |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
861 return NGX_CONF_ERROR; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
862 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
863 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
864 hv->always = 1; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
865 |
573 | 866 return NGX_CONF_OK; |
867 } |