Mercurial > hg > nginx
comparison src/http/modules/ngx_http_headers_filter_module.c @ 5941:36e61455a8f4
Headers filter: local variables for config, no functional changes.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 11 Dec 2014 23:42:06 +0300 |
parents | 74ffe03555d0 |
children | 4983f7d18fe3 |
comparison
equal
deleted
inserted
replaced
5940:e3b3b89d74e8 | 5941:36e61455a8f4 |
---|---|
207 | 207 |
208 | 208 |
209 static ngx_int_t | 209 static ngx_int_t |
210 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf) | 210 ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf) |
211 { | 211 { |
212 size_t len; | 212 size_t len; |
213 time_t now, expires_time, max_age; | 213 time_t now, expires_time, max_age; |
214 ngx_uint_t i; | 214 ngx_uint_t i; |
215 ngx_table_elt_t *expires, *cc, **ccp; | 215 ngx_table_elt_t *e, *cc, **ccp; |
216 | 216 ngx_http_expires_t expires; |
217 expires = r->headers_out.expires; | 217 |
218 | 218 expires = conf->expires; |
219 if (expires == NULL) { | 219 expires_time = conf->expires_time; |
220 | 220 |
221 expires = ngx_list_push(&r->headers_out.headers); | 221 e = r->headers_out.expires; |
222 if (expires == NULL) { | 222 |
223 return NGX_ERROR; | 223 if (e == NULL) { |
224 } | 224 |
225 | 225 e = ngx_list_push(&r->headers_out.headers); |
226 r->headers_out.expires = expires; | 226 if (e == NULL) { |
227 | 227 return NGX_ERROR; |
228 expires->hash = 1; | 228 } |
229 ngx_str_set(&expires->key, "Expires"); | 229 |
230 r->headers_out.expires = e; | |
231 | |
232 e->hash = 1; | |
233 ngx_str_set(&e->key, "Expires"); | |
230 } | 234 } |
231 | 235 |
232 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); | 236 len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT"); |
233 expires->value.len = len - 1; | 237 e->value.len = len - 1; |
234 | 238 |
235 ccp = r->headers_out.cache_control.elts; | 239 ccp = r->headers_out.cache_control.elts; |
236 | 240 |
237 if (ccp == NULL) { | 241 if (ccp == NULL) { |
238 | 242 |
263 } | 267 } |
264 | 268 |
265 cc = ccp[0]; | 269 cc = ccp[0]; |
266 } | 270 } |
267 | 271 |
268 if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) { | 272 if (expires == NGX_HTTP_EXPIRES_EPOCH) { |
269 expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; | 273 e->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT"; |
270 ngx_str_set(&cc->value, "no-cache"); | 274 ngx_str_set(&cc->value, "no-cache"); |
271 return NGX_OK; | 275 return NGX_OK; |
272 } | 276 } |
273 | 277 |
274 if (conf->expires == NGX_HTTP_EXPIRES_MAX) { | 278 if (expires == NGX_HTTP_EXPIRES_MAX) { |
275 expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT"; | 279 e->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT"; |
276 /* 10 years */ | 280 /* 10 years */ |
277 ngx_str_set(&cc->value, "max-age=315360000"); | 281 ngx_str_set(&cc->value, "max-age=315360000"); |
278 return NGX_OK; | 282 return NGX_OK; |
279 } | 283 } |
280 | 284 |
281 expires->value.data = ngx_pnalloc(r->pool, len); | 285 e->value.data = ngx_pnalloc(r->pool, len); |
282 if (expires->value.data == NULL) { | 286 if (e->value.data == NULL) { |
283 return NGX_ERROR; | 287 return NGX_ERROR; |
284 } | 288 } |
285 | 289 |
286 if (conf->expires_time == 0 && conf->expires != NGX_HTTP_EXPIRES_DAILY) { | 290 if (expires_time == 0 && expires != NGX_HTTP_EXPIRES_DAILY) { |
287 ngx_memcpy(expires->value.data, ngx_cached_http_time.data, | 291 ngx_memcpy(e->value.data, ngx_cached_http_time.data, |
288 ngx_cached_http_time.len + 1); | 292 ngx_cached_http_time.len + 1); |
289 ngx_str_set(&cc->value, "max-age=0"); | 293 ngx_str_set(&cc->value, "max-age=0"); |
290 return NGX_OK; | 294 return NGX_OK; |
291 } | 295 } |
292 | 296 |
293 now = ngx_time(); | 297 now = ngx_time(); |
294 | 298 |
295 if (conf->expires == NGX_HTTP_EXPIRES_DAILY) { | 299 if (expires == NGX_HTTP_EXPIRES_DAILY) { |
296 expires_time = ngx_next_time(conf->expires_time); | 300 expires_time = ngx_next_time(expires_time); |
297 max_age = expires_time - now; | 301 max_age = expires_time - now; |
298 | 302 |
299 } else if (conf->expires == NGX_HTTP_EXPIRES_ACCESS | 303 } else if (expires == NGX_HTTP_EXPIRES_ACCESS |
300 || r->headers_out.last_modified_time == -1) | 304 || r->headers_out.last_modified_time == -1) |
301 { | 305 { |
302 expires_time = now + conf->expires_time; | 306 max_age = expires_time; |
303 max_age = conf->expires_time; | 307 expires_time += now; |
304 | 308 |
305 } else { | 309 } else { |
306 expires_time = r->headers_out.last_modified_time + conf->expires_time; | 310 expires_time += r->headers_out.last_modified_time; |
307 max_age = expires_time - now; | 311 max_age = expires_time - now; |
308 } | 312 } |
309 | 313 |
310 ngx_http_time(expires->value.data, expires_time); | 314 ngx_http_time(e->value.data, expires_time); |
311 | 315 |
312 if (conf->expires_time < 0 || max_age < 0) { | 316 if (conf->expires_time < 0 || max_age < 0) { |
313 ngx_str_set(&cc->value, "no-cache"); | 317 ngx_str_set(&cc->value, "no-cache"); |
314 return NGX_OK; | 318 return NGX_OK; |
315 } | 319 } |