Mercurial > hg > nginx
annotate src/http/modules/ngx_http_headers_filter_module.c @ 9306:e46e1ea89ccd
Upstream: $upstream_cache_age variable.
The variable reflects response age, including the time spent in the
cache and the upstream response age as obtained from the "Age" header.
If the response wasn't cached, the variable reflects the "Age" header
of the upstream response.
If the intended use case is to cache responses as per HTTP/1.1 caching
model, the $upstream_cache_age variable can be used to provide the "Age"
header with the "add_header" directive, such as:
add_header Age $upstream_cache_age;
This now removes the "Age" header if it was present.
Further, the "expires" directives now removes the "Age" header if it
was present in the response, as the "expires" directive assumes zero
age when it adds "Expires" and "Cache-Control" headers.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 18 Jul 2024 19:39:45 +0300 |
parents | e64a1f32065b |
children |
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 |
9306
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
96 { ngx_string("Age"), |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
97 offsetof(ngx_http_headers_out_t, age), |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
98 ngx_http_set_response_header }, |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
99 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
100 { ngx_null_string, 0, NULL } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
101 }; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
102 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
103 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
104 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
|
105 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 { ngx_string("expires"), |
573 | 107 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
2013 | 108 |NGX_CONF_TAKE12, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 ngx_http_headers_expires, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 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
|
111 0, |
7017
057ec63be834
Headers filter: style.
Piotr Sikora <piotrsikora@google.com>
parents:
6986
diff
changeset
|
112 NULL }, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 |
573 | 114 { ngx_string("add_header"), |
115 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
|
116 |NGX_CONF_TAKE23, |
573 | 117 ngx_http_headers_add, |
118 NGX_HTTP_LOC_CONF_OFFSET, | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
119 offsetof(ngx_http_headers_conf_t, headers), |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
120 NULL }, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
121 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
122 { ngx_string("add_trailer"), |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
123 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
|
124 |NGX_CONF_TAKE23, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
125 ngx_http_headers_add, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
126 NGX_HTTP_LOC_CONF_OFFSET, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
127 offsetof(ngx_http_headers_conf_t, trailers), |
7017
057ec63be834
Headers filter: style.
Piotr Sikora <piotrsikora@google.com>
parents:
6986
diff
changeset
|
128 NULL }, |
573 | 129 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 ngx_null_command |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
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 static ngx_http_module_t ngx_http_headers_filter_module_ctx = { |
509 | 135 NULL, /* preconfiguration */ |
681 | 136 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
|
137 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 NULL, /* create main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
139 NULL, /* init main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
141 NULL, /* create server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 NULL, /* merge server configuration */ |
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 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
|
145 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
|
146 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
149 ngx_module_t ngx_http_headers_filter_module = { |
509 | 150 NGX_MODULE_V1, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
151 &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
|
152 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
|
153 NGX_HTTP_MODULE, /* module type */ |
541 | 154 NULL, /* init master */ |
681 | 155 NULL, /* init module */ |
541 | 156 NULL, /* init process */ |
157 NULL, /* init thread */ | |
158 NULL, /* exit thread */ | |
159 NULL, /* exit process */ | |
160 NULL, /* exit master */ | |
161 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
|
162 }; |
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 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 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
|
166 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
|
167 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
501 | 169 static ngx_int_t |
170 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
|
171 { |
1364 | 172 ngx_str_t value; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
173 ngx_uint_t i, safe_status; |
625 | 174 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
|
175 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
|
176 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
177 if (r != r->main) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
178 return ngx_http_next_header_filter(r); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
179 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
180 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
181 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
|
182 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
183 if (conf->expires == NGX_HTTP_EXPIRES_OFF |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
184 && conf->headers == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
185 && conf->trailers == NULL) |
543 | 186 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 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
|
188 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
190 switch (r->headers_out.status) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
191 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
192 case NGX_HTTP_OK: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
193 case NGX_HTTP_CREATED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
194 case NGX_HTTP_NO_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
195 case NGX_HTTP_PARTIAL_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
196 case NGX_HTTP_MOVED_PERMANENTLY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
197 case NGX_HTTP_MOVED_TEMPORARILY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
198 case NGX_HTTP_SEE_OTHER: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
199 case NGX_HTTP_NOT_MODIFIED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
200 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
|
201 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
|
202 safe_status = 1; |
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 default: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
206 safe_status = 0; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
207 break; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
208 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
209 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
210 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
|
211 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
|
212 return NGX_ERROR; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
213 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
214 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
215 |
573 | 216 if (conf->headers) { |
217 h = conf->headers->elts; | |
218 for (i = 0; i < conf->headers->nelts; i++) { | |
625 | 219 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
220 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
|
221 continue; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
222 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
223 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
224 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
|
225 return NGX_ERROR; |
625 | 226 } |
227 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
228 if (h[i].handler(r, &h[i], &value) != NGX_OK) { |
625 | 229 return NGX_ERROR; |
230 } | |
573 | 231 } |
232 } | |
233 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
234 if (conf->trailers) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
235 h = conf->trailers->elts; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
236 for (i = 0; i < conf->trailers->nelts; i++) { |
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 if (!safe_status && !h[i].always) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
239 continue; |
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 r->expect_trailers = 1; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
243 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
244 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
245 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
246 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
247 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
|
248 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
249 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
250 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
251 static ngx_int_t |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
252 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
|
253 { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
254 ngx_str_t value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
255 ngx_uint_t i, safe_status; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
256 ngx_chain_t *cl; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
257 ngx_table_elt_t *t; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
258 ngx_http_header_val_t *h; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
259 ngx_http_headers_conf_t *conf; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
260 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
261 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
|
262 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
263 if (in == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
264 || conf->trailers == NULL |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
265 || !r->expect_trailers |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
266 || r->header_only) |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
267 { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
268 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
269 } |
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 for (cl = in; cl; cl = cl->next) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
272 if (cl->buf->last_buf) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
273 break; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
274 } |
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 if (cl == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
278 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
279 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
280 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
281 switch (r->headers_out.status) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
282 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
283 case NGX_HTTP_OK: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
284 case NGX_HTTP_CREATED: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
285 case NGX_HTTP_NO_CONTENT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
286 case NGX_HTTP_PARTIAL_CONTENT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
287 case NGX_HTTP_MOVED_PERMANENTLY: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
288 case NGX_HTTP_MOVED_TEMPORARILY: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
289 case NGX_HTTP_SEE_OTHER: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
290 case NGX_HTTP_NOT_MODIFIED: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
291 case NGX_HTTP_TEMPORARY_REDIRECT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
292 case NGX_HTTP_PERMANENT_REDIRECT: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
293 safe_status = 1; |
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 default: |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
297 safe_status = 0; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
298 break; |
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 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
301 h = conf->trailers->elts; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
302 for (i = 0; i < conf->trailers->nelts; i++) { |
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 (!safe_status && !h[i].always) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
305 continue; |
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 (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
|
309 return NGX_ERROR; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
310 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
311 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
312 if (value.len) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
313 t = ngx_list_push(&r->headers_out.trailers); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
314 if (t == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
315 return NGX_ERROR; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
316 } |
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 t->key = h[i].key; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
319 t->value = value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
320 t->hash = 1; |
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 return ngx_http_next_body_filter(r, in); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
325 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
326 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
327 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
328 static ngx_int_t |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
329 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
|
330 { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
331 char *err; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
332 size_t len; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
333 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
|
334 ngx_str_t value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
335 ngx_int_t rc; |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
336 ngx_table_elt_t *e, *cc; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
337 ngx_http_expires_t expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
338 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
339 expires = conf->expires; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
340 expires_time = conf->expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
341 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
342 if (conf->expires_value != NULL) { |
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 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
|
345 return NGX_ERROR; |
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 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
348 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
|
349 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
350 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
351 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
352 } |
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 if (expires == NGX_HTTP_EXPIRES_OFF) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
355 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
356 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
357 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
358 |
9306
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
359 if (r->headers_out.age) { |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
360 r->headers_out.age->hash = 0; |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
361 r->headers_out.age = NULL; |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
362 } |
e46e1ea89ccd
Upstream: $upstream_cache_age variable.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8039
diff
changeset
|
363 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
364 e = r->headers_out.expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
365 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
366 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
367 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
368 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
|
369 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
370 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
371 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
372 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
373 r->headers_out.expires = e; |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
374 e->next = NULL; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
375 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
376 e->hash = 1; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
377 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
|
378 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
379 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
380 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
|
381 e->value.len = len - 1; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
382 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
383 cc = r->headers_out.cache_control; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
384 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
385 if (cc == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
386 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
387 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
|
388 if (cc == NULL) { |
8039
e64a1f32065b
Headers filter: improved memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8031
diff
changeset
|
389 e->hash = 0; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
390 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
391 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
392 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
393 r->headers_out.cache_control = cc; |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
394 cc->next = NULL; |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
395 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
396 cc->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
397 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
|
398 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
399 } else { |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
400 for (cc = cc->next; cc; cc = cc->next) { |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
401 cc->hash = 0; |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
402 } |
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
403 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
404 cc = r->headers_out.cache_control; |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
405 cc->next = NULL; |
1366
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) { |
8039
e64a1f32065b
Headers filter: improved memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8031
diff
changeset
|
423 e->hash = 0; |
e64a1f32065b
Headers filter: improved memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8031
diff
changeset
|
424 cc->hash = 0; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
425 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
426 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
427 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
428 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
|
429 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
|
430 ngx_cached_http_time.len + 1); |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
431 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
|
432 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
433 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
434 |
2163 | 435 now = ngx_time(); |
436 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
437 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
|
438 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
|
439 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
|
440 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
441 } 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
|
442 || r->headers_out.last_modified_time == -1) |
2013 | 443 { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
444 max_age = expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
445 expires_time += now; |
2163 | 446 |
2013 | 447 } else { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
448 expires_time += r->headers_out.last_modified_time; |
2163 | 449 max_age = expires_time - now; |
2013 | 450 } |
451 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
452 ngx_http_time(e->value.data, expires_time); |
2013 | 453 |
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
|
454 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
|
455 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
|
456 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
457 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
458 |
2049 | 459 cc->value.data = ngx_pnalloc(r->pool, |
460 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
|
461 if (cc->value.data == NULL) { |
8039
e64a1f32065b
Headers filter: improved memory allocation error handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8031
diff
changeset
|
462 cc->hash = 0; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
463 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
464 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
465 |
2163 | 466 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
|
467 - cc->value.data; |
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 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
470 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
471 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
472 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
473 static ngx_int_t |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
474 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
|
475 time_t *expires_time, char **err) |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
476 { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
477 ngx_uint_t minus; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
478 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
479 if (*expires != NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
480 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
481 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
|
482 *expires = NGX_HTTP_EXPIRES_EPOCH; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
483 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
484 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
485 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
486 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
|
487 *expires = NGX_HTTP_EXPIRES_MAX; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
488 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
489 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
490 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
491 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
|
492 *expires = NGX_HTTP_EXPIRES_OFF; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
493 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
494 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
495 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
496 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
497 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
|
498 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
499 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
500 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
501 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
502 if (*expires == NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
503 *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
|
504 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
505 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
506 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
507 *expires = NGX_HTTP_EXPIRES_DAILY; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
508 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
509 } 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
|
510 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
511 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
512 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
513 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
514 } 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
|
515 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
516 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
517 minus = 1; |
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 } else { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
520 minus = 0; |
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 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
523 *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
|
524 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
525 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
|
526 *err = "invalid value"; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
527 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
528 } |
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 if (*expires == NGX_HTTP_EXPIRES_DAILY |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
531 && *expires_time > 24 * 60 * 60) |
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 *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
|
534 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
535 } |
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 if (minus) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
538 *expires_time = - *expires_time; |
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 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
542 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
543 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
544 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
545 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
546 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
|
547 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
548 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
549 ngx_table_elt_t *h; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
550 |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
551 if (value->len) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
552 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
|
553 if (h == NULL) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
554 return NGX_ERROR; |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
555 } |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
556 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
557 h->hash = 1; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
558 h->key = hv->key; |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
559 h->value = *value; |
1363
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 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
563 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
564 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
565 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
566 static ngx_int_t |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
567 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
|
568 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
|
569 { |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
570 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
|
571 |
5427
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
572 if (value->len == 0) { |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
573 return NGX_OK; |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
574 } |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
575 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
576 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
|
577 if (h == NULL) { |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
578 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
579 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
580 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
581 h->hash = 1; |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
582 h->key = hv->key; |
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
583 h->value = *value; |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
584 |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
585 ph = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
586 |
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
587 while (*ph) { ph = &(*ph)->next; } |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6977
diff
changeset
|
588 |
7199
6ba68ad8b24c
Basic support of the Link response header.
Ruslan Ermilov <ru@nginx.com>
parents:
7036
diff
changeset
|
589 *ph = h; |
8024
ef6a3a99a81a
Reworked multi headers to use linked lists.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7199
diff
changeset
|
590 h->next = NULL; |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
591 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
592 return NGX_OK; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
593 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
594 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
595 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
596 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
597 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
|
598 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
599 { |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
600 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
|
601 return NGX_ERROR; |
3cb5cf1e1439
Added Last-Modified parsing in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4548
diff
changeset
|
602 } |
1655 | 603 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
604 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
|
605 (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
|
606 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
607 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
608 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
609 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
610 |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
611 static ngx_int_t |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
612 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
|
613 ngx_str_t *value) |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
614 { |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
615 ngx_table_elt_t *h, **old; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
616 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
617 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
|
618 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
619 if (value->len == 0) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
620 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
621 (*old)->hash = 0; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
622 *old = NULL; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
623 } |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
624 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
625 return NGX_OK; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
626 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
627 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
628 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
629 h = *old; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
630 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
631 } else { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
632 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
|
633 if (h == NULL) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
634 return NGX_ERROR; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
635 } |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
636 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
637 *old = h; |
8031
d26db4f82d7d
All known output headers can be linked lists now.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8024
diff
changeset
|
638 h->next = NULL; |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
639 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
640 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
641 h->hash = 1; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
642 h->key = hv->key; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
643 h->value = *value; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
644 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
645 return NGX_OK; |
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 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
648 |
501 | 649 static void * |
650 ngx_http_headers_create_conf(ngx_conf_t *cf) | |
577 | 651 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
652 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
|
653 |
573 | 654 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t)); |
501 | 655 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
|
656 return NULL; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
657 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
658 |
573 | 659 /* |
660 * set by ngx_pcalloc(): | |
661 * | |
662 * conf->headers = NULL; | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
663 * conf->trailers = NULL; |
2013 | 664 * conf->expires_time = 0; |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
665 * conf->expires_value = NULL; |
573 | 666 */ |
667 | |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
668 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
|
669 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
670 return conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
671 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
672 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
673 |
501 | 674 static char * |
675 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
|
676 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
677 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
|
678 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
|
679 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
680 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 681 conf->expires = prev->expires; |
682 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
|
683 conf->expires_value = prev->expires_value; |
2013 | 684 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
685 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 686 conf->expires = NGX_HTTP_EXPIRES_OFF; |
687 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
688 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
689 |
573 | 690 if (conf->headers == NULL) { |
691 conf->headers = prev->headers; | |
692 } | |
693 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
694 if (conf->trailers == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
695 conf->trailers = prev->trailers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
696 } |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
697 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
698 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
699 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
700 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
701 |
681 | 702 static ngx_int_t |
703 ngx_http_headers_filter_init(ngx_conf_t *cf) | |
704 { | |
705 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
706 ngx_http_top_header_filter = ngx_http_headers_filter; | |
707 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
708 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
|
709 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
|
710 |
681 | 711 return NGX_OK; |
712 } | |
713 | |
714 | |
501 | 715 static char * |
716 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
|
717 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
718 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
|
719 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
720 char *err; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
721 ngx_str_t *value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
722 ngx_int_t rc; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
723 ngx_uint_t n; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
724 ngx_http_complex_value_t cv; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
725 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
|
726 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
727 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
|
728 return "is duplicate"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
729 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
730 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
731 value = cf->args->elts; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
732 |
2013 | 733 if (cf->args->nelts == 2) { |
734 | |
735 hcf->expires = NGX_HTTP_EXPIRES_ACCESS; | |
736 | |
737 n = 1; | |
738 | |
739 } else { /* cf->args->nelts == 3 */ | |
740 | |
741 if (ngx_strcmp(value[1].data, "modified") != 0) { | |
742 return "invalid value"; | |
743 } | |
744 | |
745 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; | |
746 | |
747 n = 2; | |
729 | 748 } |
749 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
750 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
|
751 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
752 ccv.cf = cf; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
753 ccv.value = &value[n]; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
754 ccv.complex_value = &cv; |
2163 | 755 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
756 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
|
757 return NGX_CONF_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
758 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
759 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
760 if (cv.lengths != NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
761 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
762 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
|
763 sizeof(ngx_http_complex_value_t)); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
764 if (hcf->expires_value == NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
765 return NGX_CONF_ERROR; |
2163 | 766 } |
767 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
768 *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
|
769 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
770 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
|
771 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
772 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
773 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
|
774 &err); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
775 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
776 return err; |
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 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
779 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
780 } |
573 | 781 |
782 | |
783 static char * | |
784 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
785 { | |
786 ngx_http_headers_conf_t *hcf = conf; | |
787 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
788 ngx_str_t *value; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
789 ngx_uint_t i; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
790 ngx_array_t **headers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
791 ngx_http_header_val_t *hv; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
792 ngx_http_set_header_t *set; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
793 ngx_http_compile_complex_value_t ccv; |
573 | 794 |
795 value = cf->args->elts; | |
796 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
797 headers = (ngx_array_t **) ((char *) hcf + cmd->offset); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
798 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
799 if (*headers == NULL) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
800 *headers = ngx_array_create(cf->pool, 1, |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
801 sizeof(ngx_http_header_val_t)); |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
802 if (*headers == NULL) { |
573 | 803 return NGX_CONF_ERROR; |
804 } | |
805 } | |
806 | |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
807 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
|
808 if (hv == NULL) { |
573 | 809 return NGX_CONF_ERROR; |
810 } | |
811 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
812 hv->key = value[1]; |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
813 hv->handler = NULL; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
814 hv->offset = 0; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
815 hv->always = 0; |
625 | 816 |
7036
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
817 if (headers == &hcf->headers) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
818 hv->handler = ngx_http_add_header; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
819 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
820 set = ngx_http_set_headers; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
821 for (i = 0; set[i].name.len; i++) { |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
822 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
|
823 continue; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
824 } |
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 hv->offset = set[i].offset; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
827 hv->handler = set[i].handler; |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
828 |
8666da1ecf33
Headers filter: added "add_trailer" directive.
Piotr Sikora <piotrsikora@google.com>
parents:
7017
diff
changeset
|
829 break; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
830 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
831 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
832 |
2605
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
833 if (value[2].len == 0) { |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
834 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
|
835 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
836 } else { |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
837 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
625 | 838 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
839 ccv.cf = cf; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
840 ccv.value = &value[2]; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
841 ccv.complex_value = &hv->value; |
625 | 842 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
843 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
|
844 return NGX_CONF_ERROR; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
845 } |
625 | 846 } |
573 | 847 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
848 if (cf->args->nelts == 3) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
849 return NGX_CONF_OK; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
850 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
851 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
852 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
|
853 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
|
854 "invalid parameter \"%V\"", &value[3]); |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
855 return NGX_CONF_ERROR; |
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 hv->always = 1; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
859 |
573 | 860 return NGX_CONF_OK; |
861 } |