Mercurial > hg > nginx
annotate src/http/modules/ngx_http_headers_filter_module.c @ 6470:62d950bc0f15
Updated OpenSSL used for win32 builds.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 29 Mar 2016 09:54:11 +0300 |
parents | 5dfc63c1d9ca |
children | be5cfa918bfc |
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; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
51 } 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
|
52 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 ngx_http_expires_t *expires, time_t *expires_time, char **err); |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
58 static ngx_int_t ngx_http_add_cache_control(ngx_http_request_t *r, |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 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
|
68 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf, |
573 | 69 void *parent, void *child); |
681 | 70 static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf); |
501 | 71 static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, |
72 void *conf); | |
573 | 73 static char *ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, |
74 void *conf); | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
77 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
|
78 |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
79 { ngx_string("Cache-Control"), 0, ngx_http_add_cache_control }, |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
80 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
81 { ngx_string("Last-Modified"), |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
82 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
|
83 ngx_http_set_last_modified }, |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
84 |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
85 { ngx_string("ETag"), |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
86 offsetof(ngx_http_headers_out_t, etag), |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
87 ngx_http_set_response_header }, |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
88 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
89 { ngx_null_string, 0, NULL } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
90 }; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
91 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
92 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 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
|
94 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 { ngx_string("expires"), |
573 | 96 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
2013 | 97 |NGX_CONF_TAKE12, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 ngx_http_headers_expires, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 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
|
100 0, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 NULL}, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
573 | 103 { ngx_string("add_header"), |
104 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
|
105 |NGX_CONF_TAKE23, |
573 | 106 ngx_http_headers_add, |
107 NGX_HTTP_LOC_CONF_OFFSET, | |
108 0, | |
109 NULL}, | |
110 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 ngx_null_command |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 static ngx_http_module_t ngx_http_headers_filter_module_ctx = { |
509 | 116 NULL, /* preconfiguration */ |
681 | 117 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
|
118 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 NULL, /* create main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 NULL, /* init main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
121 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 NULL, /* create server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 NULL, /* merge server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
124 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 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
|
126 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
|
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 ngx_module_t ngx_http_headers_filter_module = { |
509 | 131 NGX_MODULE_V1, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 &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
|
133 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
|
134 NGX_HTTP_MODULE, /* module type */ |
541 | 135 NULL, /* init master */ |
681 | 136 NULL, /* init module */ |
541 | 137 NULL, /* init process */ |
138 NULL, /* init thread */ | |
139 NULL, /* exit thread */ | |
140 NULL, /* exit process */ | |
141 NULL, /* exit master */ | |
142 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
|
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 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
146 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
147 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
148 |
501 | 149 static ngx_int_t |
150 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
|
151 { |
1364 | 152 ngx_str_t value; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
153 ngx_uint_t i, safe_status; |
625 | 154 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
|
155 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
|
156 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
157 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
|
158 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
159 if ((conf->expires == NGX_HTTP_EXPIRES_OFF && conf->headers == NULL) |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
160 || r != r->main) |
543 | 161 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 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
|
163 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
165 switch (r->headers_out.status) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
166 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
167 case NGX_HTTP_OK: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
168 case NGX_HTTP_CREATED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
169 case NGX_HTTP_NO_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
170 case NGX_HTTP_PARTIAL_CONTENT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
171 case NGX_HTTP_MOVED_PERMANENTLY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
172 case NGX_HTTP_MOVED_TEMPORARILY: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
173 case NGX_HTTP_SEE_OTHER: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
174 case NGX_HTTP_NOT_MODIFIED: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
175 case NGX_HTTP_TEMPORARY_REDIRECT: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
176 safe_status = 1; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
177 break; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
178 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
179 default: |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
180 safe_status = 0; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
181 break; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
182 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
183 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
184 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
|
185 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
|
186 return NGX_ERROR; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
573 | 190 if (conf->headers) { |
191 h = conf->headers->elts; | |
192 for (i = 0; i < conf->headers->nelts; i++) { | |
625 | 193 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
194 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
|
195 continue; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
196 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
197 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
198 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
|
199 return NGX_ERROR; |
625 | 200 } |
201 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
202 if (h[i].handler(r, &h[i], &value) != NGX_OK) { |
625 | 203 return NGX_ERROR; |
204 } | |
573 | 205 } |
206 } | |
207 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
208 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
|
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 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
212 static ngx_int_t |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
213 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
|
214 { |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
215 char *err; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
216 size_t len; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
217 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
|
218 ngx_str_t value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
219 ngx_int_t rc; |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
220 ngx_uint_t i; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
221 ngx_table_elt_t *e, *cc, **ccp; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
222 ngx_http_expires_t expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
223 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
224 expires = conf->expires; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
225 expires_time = conf->expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
226 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
227 if (conf->expires_value != NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
228 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
229 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
|
230 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
231 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
232 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
233 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
|
234 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
235 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
236 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
237 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
238 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
239 if (expires == NGX_HTTP_EXPIRES_OFF) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
240 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
241 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
242 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
243 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
244 e = r->headers_out.expires; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
245 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
246 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
247 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
248 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
|
249 if (e == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
250 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
251 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
252 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
253 r->headers_out.expires = e; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
254 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
255 e->hash = 1; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
256 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
|
257 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
258 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
259 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
|
260 e->value.len = len - 1; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
261 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
262 ccp = r->headers_out.cache_control.elts; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
263 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
264 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
265 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
266 if (ngx_array_init(&r->headers_out.cache_control, r->pool, |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
267 1, sizeof(ngx_table_elt_t *)) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
268 != NGX_OK) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
269 { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
270 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
271 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
272 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
273 ccp = ngx_array_push(&r->headers_out.cache_control); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
274 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
275 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
276 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
277 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
278 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
|
279 if (cc == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
280 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
281 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
282 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
283 cc->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
284 ngx_str_set(&cc->key, "Cache-Control"); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
285 *ccp = cc; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
286 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
287 } else { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
288 for (i = 1; i < r->headers_out.cache_control.nelts; i++) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
289 ccp[i]->hash = 0; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
290 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
291 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
292 cc = ccp[0]; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
293 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
294 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
299 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
300 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
301 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
|
302 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
|
303 /* 10 years */ |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
304 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
|
305 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
306 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
307 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
308 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
|
309 if (e->value.data == NULL) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
310 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
311 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
312 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
313 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
|
314 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
|
315 ngx_cached_http_time.len + 1); |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
316 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
|
317 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
318 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
319 |
2163 | 320 now = ngx_time(); |
321 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
326 } 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
|
327 || r->headers_out.last_modified_time == -1) |
2013 | 328 { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
329 max_age = expires_time; |
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
330 expires_time += now; |
2163 | 331 |
2013 | 332 } else { |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
333 expires_time += r->headers_out.last_modified_time; |
2163 | 334 max_age = expires_time - now; |
2013 | 335 } |
336 | |
5941
36e61455a8f4
Headers filter: local variables for config, no functional changes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5817
diff
changeset
|
337 ngx_http_time(e->value.data, expires_time); |
2013 | 338 |
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
|
339 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
|
340 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
|
341 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
342 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
343 |
2049 | 344 cc->value.data = ngx_pnalloc(r->pool, |
345 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
|
346 if (cc->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
347 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
348 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
349 |
2163 | 350 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
|
351 - cc->value.data; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
352 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
353 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
354 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
355 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
356 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
357 static ngx_int_t |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
358 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
|
359 time_t *expires_time, char **err) |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
360 { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
361 ngx_uint_t minus; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
362 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
363 if (*expires != NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
364 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
365 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
|
366 *expires = NGX_HTTP_EXPIRES_EPOCH; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
367 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
368 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
369 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
370 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
|
371 *expires = NGX_HTTP_EXPIRES_MAX; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
372 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
373 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
374 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
375 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
|
376 *expires = NGX_HTTP_EXPIRES_OFF; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
377 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
378 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
379 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
380 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
381 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
|
382 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
383 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
384 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
385 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
386 if (*expires == NGX_HTTP_EXPIRES_MODIFIED) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
387 *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
|
388 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
389 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
390 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
391 *expires = NGX_HTTP_EXPIRES_DAILY; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
392 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
393 } 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
|
394 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
395 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
396 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
397 |
6062
173561dfd567
Fixed invalid access to complex value defined as an empty string.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5942
diff
changeset
|
398 } 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
|
399 value->data++; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
400 value->len--; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
401 minus = 1; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
402 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
403 } else { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
404 minus = 0; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
405 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
406 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
407 *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
|
408 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
409 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
|
410 *err = "invalid value"; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
411 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
412 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
413 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
414 if (*expires == NGX_HTTP_EXPIRES_DAILY |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
415 && *expires_time > 24 * 60 * 60) |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
416 { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
417 *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
|
418 return NGX_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
419 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
420 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
421 if (minus) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
422 *expires_time = - *expires_time; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
423 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
424 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
425 return NGX_OK; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
426 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
427 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
428 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
429 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
430 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
|
431 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
432 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
433 ngx_table_elt_t *h; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
434 |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
435 if (value->len) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
436 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
|
437 if (h == NULL) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
438 return NGX_ERROR; |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
439 } |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
440 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
441 h->hash = 1; |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
442 h->key = hv->key; |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
443 h->value = *value; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
444 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
445 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
446 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
447 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
448 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
449 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
450 static ngx_int_t |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
451 ngx_http_add_cache_control(ngx_http_request_t *r, ngx_http_header_val_t *hv, |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
452 ngx_str_t *value) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
453 { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
454 ngx_table_elt_t *cc, **ccp; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
455 |
5427
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
456 if (value->len == 0) { |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
457 return NGX_OK; |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
458 } |
7ed23dcfea3d
Headers filter: empty Cache-Control is no longer added.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4975
diff
changeset
|
459 |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
460 ccp = r->headers_out.cache_control.elts; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
461 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
462 if (ccp == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
463 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
464 if (ngx_array_init(&r->headers_out.cache_control, r->pool, |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
465 1, sizeof(ngx_table_elt_t *)) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
466 != NGX_OK) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
467 { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
468 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
469 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
470 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
471 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
472 ccp = ngx_array_push(&r->headers_out.cache_control); |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
473 if (ccp == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
474 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
475 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
476 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
477 cc = ngx_list_push(&r->headers_out.headers); |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
478 if (cc == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
479 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
480 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
481 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
482 cc->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3405
diff
changeset
|
483 ngx_str_set(&cc->key, "Cache-Control"); |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
484 cc->value = *value; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
485 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
486 *ccp = cc; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
487 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
488 return NGX_OK; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
489 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
490 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
491 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
492 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
493 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
|
494 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
495 { |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
496 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
|
497 return NGX_ERROR; |
3cb5cf1e1439
Added Last-Modified parsing in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4548
diff
changeset
|
498 } |
1655 | 499 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
500 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
|
501 (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
|
502 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
503 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
504 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
505 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
506 |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
507 static ngx_int_t |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
508 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
|
509 ngx_str_t *value) |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
510 { |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
511 ngx_table_elt_t *h, **old; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
512 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
513 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
|
514 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
515 if (value->len == 0) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
516 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
517 (*old)->hash = 0; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
518 *old = NULL; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
519 } |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
520 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
521 return NGX_OK; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
522 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
523 |
4974
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
524 if (*old) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
525 h = *old; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
526 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
527 } else { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
528 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
|
529 if (h == NULL) { |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
530 return NGX_ERROR; |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
531 } |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
532 |
9d9ee85db35d
Slightly optimized code that handles special headers in "add_header".
Ruslan Ermilov <ru@nginx.com>
parents:
4747
diff
changeset
|
533 *old = h; |
4747
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
534 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
535 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
536 h->hash = 1; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
537 h->key = hv->key; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
538 h->value = *value; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
539 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
540 return NGX_OK; |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
541 } |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
542 |
1e2ac45ad25d
Entity tags: handling in add_header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4742
diff
changeset
|
543 |
501 | 544 static void * |
545 ngx_http_headers_create_conf(ngx_conf_t *cf) | |
577 | 546 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
547 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
|
548 |
573 | 549 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t)); |
501 | 550 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
|
551 return NULL; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
552 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
553 |
573 | 554 /* |
555 * set by ngx_pcalloc(): | |
556 * | |
557 * conf->headers = NULL; | |
2013 | 558 * conf->expires_time = 0; |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
559 * conf->expires_value = NULL; |
573 | 560 */ |
561 | |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
562 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
|
563 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
564 return conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
565 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
566 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
567 |
501 | 568 static char * |
569 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
|
570 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
571 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
|
572 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
|
573 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
574 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 575 conf->expires = prev->expires; |
576 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
|
577 conf->expires_value = prev->expires_value; |
2013 | 578 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
579 if (conf->expires == NGX_HTTP_EXPIRES_UNSET) { |
2013 | 580 conf->expires = NGX_HTTP_EXPIRES_OFF; |
581 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
582 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
583 |
573 | 584 if (conf->headers == NULL) { |
585 conf->headers = prev->headers; | |
586 } | |
587 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
588 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
589 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
590 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
591 |
681 | 592 static ngx_int_t |
593 ngx_http_headers_filter_init(ngx_conf_t *cf) | |
594 { | |
595 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
596 ngx_http_top_header_filter = ngx_http_headers_filter; | |
597 | |
598 return NGX_OK; | |
599 } | |
600 | |
601 | |
501 | 602 static char * |
603 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
|
604 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
605 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
|
606 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
607 char *err; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
608 ngx_str_t *value; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
609 ngx_int_t rc; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
610 ngx_uint_t n; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
611 ngx_http_complex_value_t cv; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
612 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
|
613 |
4547
2577c27cbffd
Minor ngx_http_headers_filter_module.c code cleanup.
Ruslan Ermilov <ru@nginx.com>
parents:
4491
diff
changeset
|
614 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
|
615 return "is duplicate"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
616 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
617 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
618 value = cf->args->elts; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
619 |
2013 | 620 if (cf->args->nelts == 2) { |
621 | |
622 hcf->expires = NGX_HTTP_EXPIRES_ACCESS; | |
623 | |
624 n = 1; | |
625 | |
626 } else { /* cf->args->nelts == 3 */ | |
627 | |
628 if (ngx_strcmp(value[1].data, "modified") != 0) { | |
629 return "invalid value"; | |
630 } | |
631 | |
632 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; | |
633 | |
634 n = 2; | |
729 | 635 } |
636 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
637 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
|
638 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
639 ccv.cf = cf; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
640 ccv.value = &value[n]; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
641 ccv.complex_value = &cv; |
2163 | 642 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
643 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
|
644 return NGX_CONF_ERROR; |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
645 } |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
646 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
647 if (cv.lengths != NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
648 |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
649 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
|
650 sizeof(ngx_http_complex_value_t)); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
651 if (hcf->expires_value == NULL) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
652 return NGX_CONF_ERROR; |
2163 | 653 } |
654 | |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
655 *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
|
656 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
657 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
|
658 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
659 |
5942
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
660 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
|
661 &err); |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
662 if (rc != NGX_OK) { |
4983f7d18fe3
Headers filter: variables support in expires (ticket #113).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5941
diff
changeset
|
663 return err; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
664 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
665 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
666 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
667 } |
573 | 668 |
669 | |
670 static char * | |
671 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
672 { | |
673 ngx_http_headers_conf_t *hcf = conf; | |
674 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
675 ngx_str_t *value; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
676 ngx_uint_t i; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
677 ngx_http_header_val_t *hv; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
678 ngx_http_set_header_t *set; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
679 ngx_http_compile_complex_value_t ccv; |
573 | 680 |
681 value = cf->args->elts; | |
682 | |
683 if (hcf->headers == NULL) { | |
625 | 684 hcf->headers = ngx_array_create(cf->pool, 1, |
685 sizeof(ngx_http_header_val_t)); | |
573 | 686 if (hcf->headers == NULL) { |
687 return NGX_CONF_ERROR; | |
688 } | |
689 } | |
690 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
691 hv = ngx_array_push(hcf->headers); |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
692 if (hv == NULL) { |
573 | 693 return NGX_CONF_ERROR; |
694 } | |
695 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
696 hv->key = value[1]; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
697 hv->handler = ngx_http_add_header; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
698 hv->offset = 0; |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
699 hv->always = 0; |
625 | 700 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
701 set = ngx_http_set_headers; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
702 for (i = 0; set[i].name.len; i++) { |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
703 if (ngx_strcasecmp(value[1].data, set[i].name.data) != 0) { |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
704 continue; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
705 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
706 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
707 hv->offset = set[i].offset; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
708 hv->handler = set[i].handler; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
709 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
710 break; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
711 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
712 |
2605
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
713 if (value[2].len == 0) { |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
714 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
|
715 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
716 } else { |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
717 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
625 | 718 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
719 ccv.cf = cf; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
720 ccv.value = &value[2]; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
721 ccv.complex_value = &hv->value; |
625 | 722 |
6405
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
723 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
|
724 return NGX_CONF_ERROR; |
5dfc63c1d9ca
Headers filter: fixed "add_header ... '' always".
Ruslan Ermilov <ru@nginx.com>
parents:
6180
diff
changeset
|
725 } |
625 | 726 } |
573 | 727 |
5817
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
728 if (cf->args->nelts == 3) { |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
729 return NGX_CONF_OK; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
730 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
731 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
732 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
|
733 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
|
734 "invalid parameter \"%V\"", &value[3]); |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
735 return NGX_CONF_ERROR; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
736 } |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
737 |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
738 hv->always = 1; |
74ffe03555d0
Headers filter: "add_header" with "always" parameter (ticket #98).
Sergey Kandaurov <pluknet@nginx.com>
parents:
5427
diff
changeset
|
739 |
573 | 740 return NGX_CONF_OK; |
741 } |