Mercurial > hg > nginx
comparison src/http/modules/ngx_http_headers_filter_module.c @ 2163:3e8a4d057b77
expires daily time
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 11 Aug 2008 15:28:35 +0000 |
parents | 2a92804f4109 |
children | b4ffe603fa86 |
comparison
equal
deleted
inserted
replaced
2162:429269167fab | 2163:3e8a4d057b77 |
---|---|
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] == '-') { |