Mercurial > hg > nginx
annotate src/http/modules/ngx_http_headers_filter_module.c @ 2213:8cc552c91cd2
bump version
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 26 Aug 2008 17:23:27 +0000 |
parents | b4ffe603fa86 |
children | 008777fa59e0 |
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 { | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
19 ngx_str_t name; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
20 ngx_uint_t offset; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
21 ngx_http_set_header_pt handler; |
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 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
26 ngx_table_elt_t value; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
27 ngx_uint_t offset; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
28 ngx_http_set_header_pt handler; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
29 ngx_array_t *lengths; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
30 ngx_array_t *values; |
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 |
165 if (h[i].lengths == NULL) { | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
166 value = h[i].value.value; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
167 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
168 } else { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
169 if (ngx_http_script_run(r, &value, h[i].lengths->elts, 0, |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
170 h[i].values->elts) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
171 == NULL) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
172 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
173 return NGX_ERROR; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
174 } |
625 | 175 } |
176 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
177 if (h[i].handler(r, &h[i], &value) != NGX_OK) { |
625 | 178 return NGX_ERROR; |
179 } | |
573 | 180 } |
181 } | |
182 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 return ngx_http_next_header_filter(r); |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
187 static ngx_int_t |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
188 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
|
189 { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
190 size_t len; |
2163 | 191 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
|
192 ngx_uint_t i; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
193 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
|
194 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
195 expires = r->headers_out.expires; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
196 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
197 if (expires == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
198 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
199 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
|
200 if (expires == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
201 return NGX_ERROR; |
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 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
204 r->headers_out.expires = expires; |
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 expires->hash = 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
207 expires->key.len = sizeof("Expires") - 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
208 expires->key.data = (u_char *) "Expires"; |
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 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
211 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
|
212 expires->value.len = len - 1; |
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 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
|
215 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
216 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
217 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
218 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
|
219 1, sizeof(ngx_table_elt_t *)) |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
220 != NGX_OK) |
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 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
223 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
224 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
225 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
|
226 if (ccp == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
227 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
228 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
229 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
230 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
|
231 if (cc == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
232 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
233 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
234 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
235 cc->hash = 1; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
236 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
|
237 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
|
238 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
239 *ccp = cc; |
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 } else { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
242 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
|
243 ccp[i]->hash = 0; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
244 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
245 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
246 cc = ccp[0]; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
247 } |
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 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
|
250 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
|
251 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
252 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
|
253 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
|
254 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
255 return NGX_OK; |
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 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
258 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
|
259 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
|
260 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
261 /* 10 years */ |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
262 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
|
263 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
|
264 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
265 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
266 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
267 |
2049 | 268 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
|
269 if (expires->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
270 return NGX_ERROR; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
271 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
272 |
2013 | 273 if (conf->expires_time == 0) { |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
274 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
|
275 ngx_cached_http_time.len + 1); |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
276 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
277 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
|
278 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
|
279 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
280 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
281 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
282 |
2163 | 283 now = ngx_time(); |
284 | |
2013 | 285 if (conf->expires == NGX_HTTP_EXPIRES_ACCESS |
286 || r->headers_out.last_modified_time == -1) | |
287 { | |
2163 | 288 expires_time = now + conf->expires_time; |
289 max_age = conf->expires_time; | |
290 | |
291 } else if (conf->expires == NGX_HTTP_EXPIRES_DAILY) { | |
292 expires_time = ngx_next_time(conf->expires_time); | |
293 max_age = expires_time - now; | |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
294 |
2013 | 295 } else { |
2163 | 296 expires_time = r->headers_out.last_modified_time + conf->expires_time; |
297 max_age = expires_time - now; | |
2013 | 298 } |
299 | |
2163 | 300 ngx_http_time(expires->value.data, expires_time); |
2013 | 301 |
302 if (conf->expires_time < 0) { | |
1366
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
303 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
|
304 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
|
305 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
306 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
307 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
308 |
2049 | 309 cc->value.data = ngx_pnalloc(r->pool, |
310 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
|
311 if (cc->value.data == NULL) { |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
312 return NGX_ERROR; |
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 |
2163 | 315 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
|
316 - cc->value.data; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
317 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
318 return NGX_OK; |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
319 } |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
320 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
321 |
279210f24408
move "Expires" header code to a separate function
Igor Sysoev <igor@sysoev.ru>
parents:
1365
diff
changeset
|
322 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
323 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
|
324 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
325 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
326 ngx_table_elt_t *h; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
327 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
328 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
|
329 if (h == NULL) { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
330 return NGX_ERROR; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
331 } |
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 h->hash = hv->value.hash; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
334 h->key = hv->value.key; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
335 h->value = *value; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
336 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
337 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
338 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
339 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
340 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
341 static ngx_int_t |
1365
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
342 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
|
343 ngx_str_t *value) |
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 ngx_table_elt_t *cc, **ccp; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
346 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
347 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
|
348 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
349 if (ccp == NULL) { |
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 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
|
352 1, sizeof(ngx_table_elt_t *)) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
353 != NGX_OK) |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
354 { |
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 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
359 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
|
360 if (ccp == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
361 return NGX_ERROR; |
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 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
364 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
|
365 if (cc == NULL) { |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
366 return NGX_ERROR; |
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 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
369 cc->hash = 1; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
370 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
|
371 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
|
372 cc->value = *value; |
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 *ccp = cc; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
375 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
376 return NGX_OK; |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
377 } |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
378 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
379 |
d1dc7ef7c3ce
move "Cache-Control" header code to specific handler
Igor Sysoev <igor@sysoev.ru>
parents:
1364
diff
changeset
|
380 static ngx_int_t |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
381 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
|
382 ngx_str_t *value) |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
383 { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
384 ngx_table_elt_t *h, **old; |
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 if (hv->offset) { |
1364 | 387 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
|
388 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
389 } else { |
1364 | 390 old = NULL; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
391 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
392 |
1655 | 393 r->headers_out.last_modified_time = -1; |
394 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
395 if (old == NULL || *old == NULL) { |
1655 | 396 |
397 if (value->len == 0) { | |
398 return NGX_OK; | |
399 } | |
400 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
401 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
|
402 if (h == NULL) { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
403 return NGX_ERROR; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
404 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
405 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
406 } else { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
407 h = *old; |
1655 | 408 |
409 if (value->len == 0) { | |
410 h->hash = 0; | |
411 return NGX_OK; | |
412 } | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
413 } |
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 h->hash = hv->value.hash; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
416 h->key = hv->value.key; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
417 h->value = *value; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
418 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
419 return NGX_OK; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
420 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
421 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
422 |
501 | 423 static void * |
424 ngx_http_headers_create_conf(ngx_conf_t *cf) | |
577 | 425 { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
426 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
|
427 |
573 | 428 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_headers_conf_t)); |
501 | 429 if (conf == NULL) { |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
430 return NGX_CONF_ERROR; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
431 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
432 |
573 | 433 /* |
434 * set by ngx_pcalloc(): | |
435 * | |
436 * conf->headers = NULL; | |
2013 | 437 * conf->expires_time = 0; |
573 | 438 */ |
439 | |
2013 | 440 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
|
441 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
442 return conf; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
443 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
444 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
445 |
501 | 446 static char * |
447 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
|
448 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
449 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
|
450 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
|
451 |
2013 | 452 if (conf->expires == NGX_CONF_UNSET_UINT) { |
453 conf->expires = prev->expires; | |
454 conf->expires_time = prev->expires_time; | |
455 | |
456 if (conf->expires == NGX_CONF_UNSET_UINT) { | |
457 conf->expires = NGX_HTTP_EXPIRES_OFF; | |
458 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
459 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
460 |
573 | 461 if (conf->headers == NULL) { |
462 conf->headers = prev->headers; | |
463 } | |
464 | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
465 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
466 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
467 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
468 |
681 | 469 static ngx_int_t |
470 ngx_http_headers_filter_init(ngx_conf_t *cf) | |
471 { | |
472 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
473 ngx_http_top_header_filter = ngx_http_headers_filter; | |
474 | |
475 return NGX_OK; | |
476 } | |
477 | |
478 | |
501 | 479 static char * |
480 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
|
481 { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
482 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
|
483 |
2013 | 484 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
|
485 ngx_str_t *value; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
486 |
2013 | 487 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
|
488 return "is duplicate"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
489 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
490 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
491 value = cf->args->elts; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
492 |
2013 | 493 if (cf->args->nelts == 2) { |
494 | |
495 if (ngx_strcmp(value[1].data, "epoch") == 0) { | |
496 hcf->expires = NGX_HTTP_EXPIRES_EPOCH; | |
497 return NGX_CONF_OK; | |
498 } | |
499 | |
500 if (ngx_strcmp(value[1].data, "max") == 0) { | |
501 hcf->expires = NGX_HTTP_EXPIRES_MAX; | |
502 return NGX_CONF_OK; | |
503 } | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
504 |
2013 | 505 if (ngx_strcmp(value[1].data, "off") == 0) { |
506 hcf->expires = NGX_HTTP_EXPIRES_OFF; | |
507 return NGX_CONF_OK; | |
508 } | |
509 | |
510 hcf->expires = NGX_HTTP_EXPIRES_ACCESS; | |
511 | |
512 n = 1; | |
513 | |
514 } else { /* cf->args->nelts == 3 */ | |
515 | |
516 if (ngx_strcmp(value[1].data, "modified") != 0) { | |
517 return "invalid value"; | |
518 } | |
519 | |
520 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; | |
521 | |
522 n = 2; | |
729 | 523 } |
524 | |
2163 | 525 if (value[n].data[0] == '@') { |
526 value[n].data++; | |
527 value[n].len--; | |
528 minus = 0; | |
529 | |
530 if (hcf->expires == NGX_HTTP_EXPIRES_MODIFIED) { | |
531 return "daily time can not be used with \"modified\" parameter"; | |
532 } | |
533 | |
534 hcf->expires = NGX_HTTP_EXPIRES_DAILY; | |
535 | |
536 } else if (value[n].data[0] == '+') { | |
2013 | 537 value[n].data++; |
538 value[n].len--; | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
539 minus = 0; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
540 |
2013 | 541 } else if (value[n].data[0] == '-') { |
542 value[n].data++; | |
543 value[n].len--; | |
326
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
544 minus = 1; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
545 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
546 } else { |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
547 minus = 0; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
548 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
549 |
2013 | 550 hcf->expires_time = ngx_parse_time(&value[n], 1); |
501 | 551 |
2013 | 552 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
|
553 return "invalid value"; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
554 } |
577 | 555 |
2164 | 556 if (hcf->expires == NGX_HTTP_EXPIRES_DAILY |
557 && hcf->expires_time > 24 * 60 * 60) | |
558 { | |
559 return "daily time value must be less than 24 hours"; | |
560 } | |
561 | |
2013 | 562 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
|
563 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
|
564 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
565 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
566 if (minus) { |
2013 | 567 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
|
568 } |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
569 |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
570 return NGX_CONF_OK; |
8733703a37f3
nginx-0.0.3-2004-04-26-00:13:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
571 } |
573 | 572 |
573 | |
574 static char * | |
575 ngx_http_headers_add(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
576 { | |
577 ngx_http_headers_conf_t *hcf = conf; | |
578 | |
625 | 579 ngx_int_t n; |
580 ngx_str_t *value; | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
581 ngx_uint_t i; |
625 | 582 ngx_http_header_val_t *h; |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
583 ngx_http_set_header_t *sh; |
625 | 584 ngx_http_script_compile_t sc; |
573 | 585 |
586 value = cf->args->elts; | |
587 | |
588 if (hcf->headers == NULL) { | |
625 | 589 hcf->headers = ngx_array_create(cf->pool, 1, |
590 sizeof(ngx_http_header_val_t)); | |
573 | 591 if (hcf->headers == NULL) { |
592 return NGX_CONF_ERROR; | |
593 } | |
594 } | |
595 | |
596 h = ngx_array_push(hcf->headers); | |
597 if (h == NULL) { | |
598 return NGX_CONF_ERROR; | |
599 } | |
600 | |
625 | 601 h->value.hash = 1; |
602 h->value.key = value[1]; | |
603 h->value.value = value[2]; | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
604 h->offset = 0; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
605 h->handler = ngx_http_add_header; |
625 | 606 h->lengths = NULL; |
607 h->values = NULL; | |
608 | |
1363
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
609 sh = ngx_http_set_headers; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
610 for (i = 0; sh[i].name.len; i++) { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
611 if (ngx_strcasecmp(value[1].data, sh[i].name.data) != 0) { |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
612 continue; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
613 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
614 |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
615 h->offset = sh[i].offset; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
616 h->handler = sh[i].handler; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
617 break; |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
618 } |
b0e114fb3bdc
use header specific handler in add_handler,
Igor Sysoev <igor@sysoev.ru>
parents:
1107
diff
changeset
|
619 |
625 | 620 n = ngx_http_script_variables_count(&value[2]); |
621 | |
622 if (n == 0) { | |
623 return NGX_CONF_OK; | |
624 } | |
625 | |
626 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | |
627 | |
628 sc.cf = cf; | |
629 sc.source = &value[2]; | |
630 sc.lengths = &h->lengths; | |
631 sc.values = &h->values; | |
632 sc.variables = n; | |
633 sc.complete_lengths = 1; | |
634 sc.complete_values = 1; | |
635 | |
636 if (ngx_http_script_compile(&sc) != NGX_OK) { | |
637 return NGX_CONF_ERROR; | |
638 } | |
573 | 639 |
640 return NGX_CONF_OK; | |
641 } |