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