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