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