Mercurial > hg > nginx
annotate src/http/modules/ngx_http_headers_filter_module.c @ 3593:a79d2ad7a2d8 stable-0.7
merge r3487, r3525:
rewrite fixes:
*) escape ampersand in argument while rewrite
*) autodetect redirect if URI is rewritten to a string starting with $scheme
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 07 Jun 2010 11:51:37 +0000 |
parents | 14b70eb95c53 |
children | dd1570b6f237 |
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 |
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
|
4 */ |
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 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
12 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
|
13 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
14 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
|
15 ngx_http_header_val_t *hv, ngx_str_t *value); |
625 | 16 |
17 | |
18 typedef struct { | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
19 ngx_str_t name; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
20 ngx_uint_t offset; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
21 ngx_http_set_header_pt handler; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
22 } ngx_http_set_header_t; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
23 |
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 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
|
26 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
|
27 ngx_uint_t hash; |
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; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
31 }; |
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 |
2013 | 34 #define NGX_HTTP_EXPIRES_OFF 0 |
35 #define NGX_HTTP_EXPIRES_EPOCH 1 | |
36 #define NGX_HTTP_EXPIRES_MAX 2 | |
37 #define NGX_HTTP_EXPIRES_ACCESS 3 | |
38 #define NGX_HTTP_EXPIRES_MODIFIED 4 | |
2163 | 39 #define NGX_HTTP_EXPIRES_DAILY 5 |
2013 | 40 |
41 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
42 typedef struct { |
2013 | 43 ngx_uint_t expires; |
44 time_t expires_time; | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
45 ngx_array_t *headers; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 } 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
|
47 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
49 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
|
50 ngx_http_headers_conf_t *conf); |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
51 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
|
52 ngx_http_header_val_t *hv, ngx_str_t *value); |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
53 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
|
54 ngx_http_header_val_t *hv, ngx_str_t *value); |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
55 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
56 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
|
57 static char *ngx_http_headers_merge_conf(ngx_conf_t *cf, |
573 | 58 void *parent, void *child); |
681 | 59 static ngx_int_t ngx_http_headers_filter_init(ngx_conf_t *cf); |
501 | 60 static char *ngx_http_headers_expires(ngx_conf_t *cf, ngx_command_t *cmd, |
61 void *conf); | |
573 | 62 static char *ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, |
63 void *conf); | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
66 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
|
67 |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
68 { 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
|
69 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
70 { ngx_string("Last-Modified"), |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
71 offsetof(ngx_http_headers_out_t, last_modified), |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
72 ngx_http_set_last_modified }, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
73 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
74 { ngx_null_string, 0, NULL } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
75 }; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
76 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
77 |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 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
|
79 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 { ngx_string("expires"), |
573 | 81 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
2013 | 82 |NGX_CONF_TAKE12, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 ngx_http_headers_expires, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 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
|
85 0, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 NULL}, |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
87 |
573 | 88 { ngx_string("add_header"), |
89 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF | |
90 |NGX_CONF_TAKE2, | |
91 ngx_http_headers_add, | |
92 NGX_HTTP_LOC_CONF_OFFSET, | |
93 0, | |
94 NULL}, | |
95 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 ngx_null_command |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 static ngx_http_module_t ngx_http_headers_filter_module_ctx = { |
509 | 101 NULL, /* preconfiguration */ |
681 | 102 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
|
103 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
104 NULL, /* create main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 NULL, /* init main configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 NULL, /* create server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 NULL, /* merge server configuration */ |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 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
|
111 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
|
112 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
114 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 ngx_module_t ngx_http_headers_filter_module = { |
509 | 116 NGX_MODULE_V1, |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
117 &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
|
118 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
|
119 NGX_HTTP_MODULE, /* module type */ |
541 | 120 NULL, /* init master */ |
681 | 121 NULL, /* init module */ |
541 | 122 NULL, /* init process */ |
123 NULL, /* init thread */ | |
124 NULL, /* exit thread */ | |
125 NULL, /* exit process */ | |
126 NULL, /* exit master */ | |
127 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
|
128 }; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
132 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 |
501 | 134 static ngx_int_t |
135 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
|
136 { |
1364 | 137 ngx_str_t value; |
509 | 138 ngx_uint_t i; |
625 | 139 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
|
140 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
|
141 |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
142 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
|
143 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
144 if ((conf->expires == NGX_HTTP_EXPIRES_OFF && conf->headers == NULL) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
145 || r != r->main |
663 | 146 || (r->headers_out.status != NGX_HTTP_OK |
147 && r->headers_out.status != NGX_HTTP_NO_CONTENT | |
148 && r->headers_out.status != NGX_HTTP_MOVED_PERMANENTLY | |
149 && r->headers_out.status != NGX_HTTP_MOVED_TEMPORARILY | |
150 && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)) | |
543 | 151 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 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
|
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 if (conf->expires != NGX_HTTP_EXPIRES_OFF) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
156 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
|
157 return NGX_ERROR; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 |
573 | 161 if (conf->headers) { |
162 h = conf->headers->elts; | |
163 for (i = 0; i < conf->headers->nelts; i++) { | |
625 | 164 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
165 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
|
166 return NGX_ERROR; |
625 | 167 } |
168 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
169 if (h[i].handler(r, &h[i], &value) != NGX_OK) { |
625 | 170 return NGX_ERROR; |
171 } | |
573 | 172 } |
173 } | |
174 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
175 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
|
176 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
177 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
179 static ngx_int_t |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
180 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
|
181 { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
182 size_t len; |
2163 | 183 time_t now, expires_time, max_age; |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
184 ngx_uint_t i; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
185 ngx_table_elt_t *expires, *cc, **ccp; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
186 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
187 expires = r->headers_out.expires; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
188 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
189 if (expires == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
190 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
191 expires = 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
|
192 if (expires == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
193 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
194 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
195 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
196 r->headers_out.expires = expires; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
197 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
198 expires->hash = 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
199 expires->key.len = sizeof("Expires") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
200 expires->key.data = (u_char *) "Expires"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
201 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
202 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
203 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
204 expires->value.len = len - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
205 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
206 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
|
207 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
208 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
209 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
210 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
|
211 1, sizeof(ngx_table_elt_t *)) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
212 != NGX_OK) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
213 { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
214 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
215 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
216 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
217 ccp = ngx_array_push(&r->headers_out.cache_control); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
218 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
219 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
220 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
221 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
222 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
|
223 if (cc == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
224 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
225 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
226 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
227 cc->hash = 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
228 cc->key.len = sizeof("Cache-Control") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
229 cc->key.data = (u_char *) "Cache-Control"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
230 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
231 *ccp = cc; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
232 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
233 } else { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
234 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
|
235 ccp[i]->hash = 0; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
236 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
237 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
238 cc = ccp[0]; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
239 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
240 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
241 if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
242 expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
243 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
244 cc->value.len = sizeof("no-cache") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
245 cc->value.data = (u_char *) "no-cache"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
246 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
247 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
248 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
249 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
250 if (conf->expires == NGX_HTTP_EXPIRES_MAX) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
251 expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
252 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
253 /* 10 years */ |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
254 cc->value.len = sizeof("max-age=315360000") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
255 cc->value.data = (u_char *) "max-age=315360000"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
256 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
257 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
258 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
259 |
2049 | 260 expires->value.data = ngx_pnalloc(r->pool, len); |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
261 if (expires->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
262 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
263 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
264 |
2013 | 265 if (conf->expires_time == 0) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
266 ngx_memcpy(expires->value.data, ngx_cached_http_time.data, |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
267 ngx_cached_http_time.len + 1); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
268 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
269 cc->value.len = sizeof("max-age=0") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
270 cc->value.data = (u_char *) "max-age=0"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
271 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
272 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
273 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
274 |
2163 | 275 now = ngx_time(); |
276 | |
2013 | 277 if (conf->expires == NGX_HTTP_EXPIRES_ACCESS |
278 || r->headers_out.last_modified_time == -1) | |
279 { | |
2163 | 280 expires_time = now + conf->expires_time; |
281 max_age = conf->expires_time; | |
282 | |
283 } else if (conf->expires == NGX_HTTP_EXPIRES_DAILY) { | |
284 expires_time = ngx_next_time(conf->expires_time); | |
285 max_age = expires_time - now; | |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
286 |
2013 | 287 } else { |
2163 | 288 expires_time = r->headers_out.last_modified_time + conf->expires_time; |
289 max_age = expires_time - now; | |
2013 | 290 } |
291 | |
2163 | 292 ngx_http_time(expires->value.data, expires_time); |
2013 | 293 |
3443 | 294 if (conf->expires_time < 0 || max_age < 0) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
295 cc->value.len = sizeof("no-cache") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
296 cc->value.data = (u_char *) "no-cache"; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
297 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
298 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
299 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
300 |
2049 | 301 cc->value.data = ngx_pnalloc(r->pool, |
302 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
|
303 if (cc->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
304 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
305 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
306 |
2163 | 307 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
|
308 - cc->value.data; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
309 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
310 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
311 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
312 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
313 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
314 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
315 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
|
316 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
317 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
318 ngx_table_elt_t *h; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
319 |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
320 if (value->len) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
321 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
|
322 if (h == NULL) { |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
323 return NGX_ERROR; |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
324 } |
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
325 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
326 h->hash = hv->hash; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
327 h->key = hv->key; |
2406
008777fa59e0
do not add header if add_header ""
Igor Sysoev <igor@sysoev.ru>
parents:
2164
diff
changeset
|
328 h->value = *value; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
329 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
330 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
331 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
332 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
333 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
334 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
335 static ngx_int_t |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
336 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
|
337 ngx_str_t *value) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
338 { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
339 ngx_table_elt_t *cc, **ccp; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
340 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
341 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
|
342 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
343 if (ccp == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
344 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
345 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
|
346 1, sizeof(ngx_table_elt_t *)) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
347 != NGX_OK) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
348 { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
349 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
350 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
351 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
352 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
353 ccp = ngx_array_push(&r->headers_out.cache_control); |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
354 if (ccp == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
355 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
356 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
357 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
358 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
|
359 if (cc == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
360 return NGX_ERROR; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
361 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
362 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
363 cc->hash = 1; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
364 cc->key.len = sizeof("Cache-Control") - 1; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
365 cc->key.data = (u_char *) "Cache-Control"; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
366 cc->value = *value; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
367 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
368 *ccp = cc; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
369 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
370 return NGX_OK; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
371 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
372 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
373 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
374 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
375 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
|
376 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
377 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
378 ngx_table_elt_t *h, **old; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
379 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
380 if (hv->offset) { |
1364 | 381 old = (ngx_table_elt_t **) ((char *) &r->headers_out + hv->offset); |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
382 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
383 } else { |
1364 | 384 old = NULL; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
385 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
386 |
1655 | 387 r->headers_out.last_modified_time = -1; |
388 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
389 if (old == NULL || *old == NULL) { |
1655 | 390 |
391 if (value->len == 0) { | |
392 return NGX_OK; | |
393 } | |
394 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
395 h = ngx_list_push(&r->headers_out.headers); |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
396 if (h == NULL) { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
397 return NGX_ERROR; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
398 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
399 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
400 } else { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
401 h = *old; |
1655 | 402 |
403 if (value->len == 0) { | |
404 h->hash = 0; | |
405 return NGX_OK; | |
406 } | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
407 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
408 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
409 h->hash = hv->hash; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
410 h->key = hv->key; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
411 h->value = *value; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
412 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
413 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
414 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
415 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
416 |
501 | 417 static void * |
418 ngx_http_headers_create_conf(ngx_conf_t *cf) | |
577 | 419 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
420 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
|
421 |
573 | 422 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t)); |
501 | 423 if (conf == NULL) { |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2605
diff
changeset
|
424 return NULL; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
425 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
426 |
573 | 427 /* |
428 * set by ngx_pcalloc(): | |
429 * | |
430 * conf->headers = NULL; | |
2013 | 431 * conf->expires_time = 0; |
573 | 432 */ |
433 | |
2013 | 434 conf->expires = NGX_CONF_UNSET_UINT; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
435 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
436 return conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
437 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
438 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
439 |
501 | 440 static char * |
441 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
|
442 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
443 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
|
444 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
|
445 |
2013 | 446 if (conf->expires == NGX_CONF_UNSET_UINT) { |
447 conf->expires = prev->expires; | |
448 conf->expires_time = prev->expires_time; | |
449 | |
450 if (conf->expires == NGX_CONF_UNSET_UINT) { | |
451 conf->expires = NGX_HTTP_EXPIRES_OFF; | |
452 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
453 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
454 |
573 | 455 if (conf->headers == NULL) { |
456 conf->headers = prev->headers; | |
457 } | |
458 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
459 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
460 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
461 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
462 |
681 | 463 static ngx_int_t |
464 ngx_http_headers_filter_init(ngx_conf_t *cf) | |
465 { | |
466 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
467 ngx_http_top_header_filter = ngx_http_headers_filter; | |
468 | |
469 return NGX_OK; | |
470 } | |
471 | |
472 | |
501 | 473 static char * |
474 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
|
475 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
476 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
|
477 |
2013 | 478 ngx_uint_t minus, n; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
479 ngx_str_t *value; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
480 |
2013 | 481 if (hcf->expires != NGX_CONF_UNSET_UINT) { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
482 return "is duplicate"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
483 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
484 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
485 value = cf->args->elts; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
486 |
2013 | 487 if (cf->args->nelts == 2) { |
488 | |
489 if (ngx_strcmp(value[1].data, "epoch") == 0) { | |
490 hcf->expires = NGX_HTTP_EXPIRES_EPOCH; | |
491 return NGX_CONF_OK; | |
492 } | |
493 | |
494 if (ngx_strcmp(value[1].data, "max") == 0) { | |
495 hcf->expires = NGX_HTTP_EXPIRES_MAX; | |
496 return NGX_CONF_OK; | |
497 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
498 |
2013 | 499 if (ngx_strcmp(value[1].data, "off") == 0) { |
500 hcf->expires = NGX_HTTP_EXPIRES_OFF; | |
501 return NGX_CONF_OK; | |
502 } | |
503 | |
504 hcf->expires = NGX_HTTP_EXPIRES_ACCESS; | |
505 | |
506 n = 1; | |
507 | |
508 } else { /* cf->args->nelts == 3 */ | |
509 | |
510 if (ngx_strcmp(value[1].data, "modified") != 0) { | |
511 return "invalid value"; | |
512 } | |
513 | |
514 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; | |
515 | |
516 n = 2; | |
729 | 517 } |
518 | |
2163 | 519 if (value[n].data[0] == '@') { |
520 value[n].data++; | |
521 value[n].len--; | |
522 minus = 0; | |
523 | |
524 if (hcf->expires == NGX_HTTP_EXPIRES_MODIFIED) { | |
525 return "daily time can not be used with \"modified\" parameter"; | |
526 } | |
527 | |
528 hcf->expires = NGX_HTTP_EXPIRES_DAILY; | |
529 | |
530 } else if (value[n].data[0] == '+') { | |
2013 | 531 value[n].data++; |
532 value[n].len--; | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
533 minus = 0; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
534 |
2013 | 535 } else if (value[n].data[0] == '-') { |
536 value[n].data++; | |
537 value[n].len--; | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
538 minus = 1; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
539 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
540 } else { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
541 minus = 0; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
542 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 |
2013 | 544 hcf->expires_time = ngx_parse_time(&value[n], 1); |
501 | 545 |
2013 | 546 if (hcf->expires_time == NGX_ERROR) { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
547 return "invalid value"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
548 } |
577 | 549 |
2164 | 550 if (hcf->expires == NGX_HTTP_EXPIRES_DAILY |
551 && hcf->expires_time > 24 * 60 * 60) | |
552 { | |
553 return "daily time value must be less than 24 hours"; | |
554 } | |
555 | |
2013 | 556 if (hcf->expires_time == NGX_PARSE_LARGE_TIME) { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
557 return "value must be less than 68 years"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
558 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
559 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
560 if (minus) { |
2013 | 561 hcf->expires_time = - hcf->expires_time; |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
562 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
563 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
564 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
565 } |
573 | 566 |
567 | |
568 static char * | |
569 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
570 { | |
571 ngx_http_headers_conf_t *hcf = conf; | |
572 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
573 ngx_str_t *value; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
574 ngx_uint_t i; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
575 ngx_http_header_val_t *hv; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
576 ngx_http_set_header_t *set; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
577 ngx_http_compile_complex_value_t ccv; |
573 | 578 |
579 value = cf->args->elts; | |
580 | |
581 if (hcf->headers == NULL) { | |
625 | 582 hcf->headers = ngx_array_create(cf->pool, 1, |
583 sizeof(ngx_http_header_val_t)); | |
573 | 584 if (hcf->headers == NULL) { |
585 return NGX_CONF_ERROR; | |
586 } | |
587 } | |
588 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
589 hv = ngx_array_push(hcf->headers); |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
590 if (hv == NULL) { |
573 | 591 return NGX_CONF_ERROR; |
592 } | |
593 | |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
594 hv->hash = 1; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
595 hv->key = value[1]; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
596 hv->handler = ngx_http_add_header; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
597 hv->offset = 0; |
625 | 598 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
599 set = ngx_http_set_headers; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
600 for (i = 0; set[i].name.len; i++) { |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
601 if (ngx_strcasecmp(value[1].data, set[i].name.data) != 0) { |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
602 continue; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
603 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
604 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
605 hv->offset = set[i].offset; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
606 hv->handler = set[i].handler; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
607 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
608 break; |
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 |
2605
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
611 if (value[2].len == 0) { |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
612 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
|
613 return NGX_CONF_OK; |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
614 } |
2a301c21256a
fix add_header Last-Modified "", broken in r2589
Igor Sysoev <igor@sysoev.ru>
parents:
2588
diff
changeset
|
615 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
616 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
625 | 617 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
618 ccv.cf = cf; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
619 ccv.value = &value[2]; |
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
620 ccv.complex_value = &hv->value; |
625 | 621 |
2588
a6954ce88b80
use complex values in add_header, auth_basic_user_file,
Igor Sysoev <igor@sysoev.ru>
parents:
2406
diff
changeset
|
622 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
625 | 623 return NGX_CONF_ERROR; |
624 } | |
573 | 625 |
626 return NGX_CONF_OK; | |
627 } |