comparison src/http/modules/ngx_http_headers_filter_module.c @ 380:3ce4580ae286 NGINX_0_6_34

nginx 0.6.34 *) Change: now the EAGAIN error returned by connect() is not considered as temporary error. *) Change: now the "gzip_vary" directive turned on issues a "Vary: Accept-Encoding" header line for uncompressed responses too. *) Feature: the "expires" directive supports daily time. *) Feature: the "Expect" request header line support. *) Feature: now the "rewrite" directive does a redirect automatically if the "https://" protocol is used. *) Bugfix: the "listen" directive parameters such as "backlog", "rcvbuf", etc. were not set, if a default server was not the first one. *) Bugfix: the "log_not_found" directive did not work for index files tests. *) Bugfix: now if FastCGI server sends a "Location" header line without status line, then nginx uses 302 status code. Thanks to Maxim Dounin. *) Bugfix: the ngx_http_flv_module did not support several values in a query string. *) Bugfix: when a request to a directory was redirected with the slash added, nginx dropped a query string from the original request.
author Igor Sysoev <http://sysoev.ru>
date Thu, 27 Nov 2008 00:00:00 +0300
parents d13234035cad
children
comparison
equal deleted inserted replaced
379:522189e0ef36 380:3ce4580ae286
34 #define NGX_HTTP_EXPIRES_OFF 0 34 #define NGX_HTTP_EXPIRES_OFF 0
35 #define NGX_HTTP_EXPIRES_EPOCH 1 35 #define NGX_HTTP_EXPIRES_EPOCH 1
36 #define NGX_HTTP_EXPIRES_MAX 2 36 #define NGX_HTTP_EXPIRES_MAX 2
37 #define NGX_HTTP_EXPIRES_ACCESS 3 37 #define NGX_HTTP_EXPIRES_ACCESS 3
38 #define NGX_HTTP_EXPIRES_MODIFIED 4 38 #define NGX_HTTP_EXPIRES_MODIFIED 4
39 #define NGX_HTTP_EXPIRES_DAILY 5
39 40
40 41
41 typedef struct { 42 typedef struct {
42 ngx_uint_t expires; 43 ngx_uint_t expires;
43 time_t expires_time; 44 time_t expires_time;
185 186
186 static ngx_int_t 187 static ngx_int_t
187 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf) 188 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
188 { 189 {
189 size_t len; 190 size_t len;
190 time_t since; 191 time_t now, expires_time, max_age;
191 ngx_uint_t i; 192 ngx_uint_t i;
192 ngx_table_elt_t *expires, *cc, **ccp; 193 ngx_table_elt_t *expires, *cc, **ccp;
193 194
194 expires = r->headers_out.expires; 195 expires = r->headers_out.expires;
195 196
277 cc->value.data = (u_char *) "max-age=0"; 278 cc->value.data = (u_char *) "max-age=0";
278 279
279 return NGX_OK; 280 return NGX_OK;
280 } 281 }
281 282
283 now = ngx_time();
284
282 if (conf->expires == NGX_HTTP_EXPIRES_ACCESS 285 if (conf->expires == NGX_HTTP_EXPIRES_ACCESS
283 || r->headers_out.last_modified_time == -1) 286 || r->headers_out.last_modified_time == -1)
284 { 287 {
285 since = ngx_time(); 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;
286 294
287 } else { 295 } else {
288 since = r->headers_out.last_modified_time; 296 expires_time = r->headers_out.last_modified_time + conf->expires_time;
289 } 297 max_age = expires_time - now;
290 298 }
291 ngx_http_time(expires->value.data, since + conf->expires_time); 299
300 ngx_http_time(expires->value.data, expires_time);
292 301
293 if (conf->expires_time < 0) { 302 if (conf->expires_time < 0) {
294 cc->value.len = sizeof("no-cache") - 1; 303 cc->value.len = sizeof("no-cache") - 1;
295 cc->value.data = (u_char *) "no-cache"; 304 cc->value.data = (u_char *) "no-cache";
296 305
301 sizeof("max-age=") + NGX_TIME_T_LEN + 1); 310 sizeof("max-age=") + NGX_TIME_T_LEN + 1);
302 if (cc->value.data == NULL) { 311 if (cc->value.data == NULL) {
303 return NGX_ERROR; 312 return NGX_ERROR;
304 } 313 }
305 314
306 cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", 315 cc->value.len = ngx_sprintf(cc->value.data, "max-age=%T", max_age)
307 since + conf->expires_time - ngx_time())
308 - cc->value.data; 316 - cc->value.data;
309 317
310 return NGX_OK; 318 return NGX_OK;
311 } 319 }
312 320
512 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED; 520 hcf->expires = NGX_HTTP_EXPIRES_MODIFIED;
513 521
514 n = 2; 522 n = 2;
515 } 523 }
516 524
517 if (value[n].data[0] == '+') { 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] == '+') {
518 value[n].data++; 537 value[n].data++;
519 value[n].len--; 538 value[n].len--;
520 minus = 0; 539 minus = 0;
521 540
522 } else if (value[n].data[0] == '-') { 541 } else if (value[n].data[0] == '-') {
530 549
531 hcf->expires_time = ngx_parse_time(&value[n], 1); 550 hcf->expires_time = ngx_parse_time(&value[n], 1);
532 551
533 if (hcf->expires_time == NGX_ERROR) { 552 if (hcf->expires_time == NGX_ERROR) {
534 return "invalid value"; 553 return "invalid value";
554 }
555
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";
535 } 560 }
536 561
537 if (hcf->expires_time == NGX_PARSE_LARGE_TIME) { 562 if (hcf->expires_time == NGX_PARSE_LARGE_TIME) {
538 return "value must be less than 68 years"; 563 return "value must be less than 68 years";
539 } 564 }