mirror of
https://github.com/nginx/nginx.git
synced 2024-12-20 06:03:31 -06:00
Headers filter: local variables for config, no functional changes.
This commit is contained in:
parent
fb7d63250e
commit
cf21308885
@ -209,28 +209,32 @@ ngx_http_headers_filter(ngx_http_request_t *r)
|
|||||||
static ngx_int_t
|
static ngx_int_t
|
||||||
ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
|
ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
time_t now, expires_time, max_age;
|
time_t now, expires_time, max_age;
|
||||||
ngx_uint_t i;
|
ngx_uint_t i;
|
||||||
ngx_table_elt_t *expires, *cc, **ccp;
|
ngx_table_elt_t *e, *cc, **ccp;
|
||||||
|
ngx_http_expires_t expires;
|
||||||
|
|
||||||
expires = r->headers_out.expires;
|
expires = conf->expires;
|
||||||
|
expires_time = conf->expires_time;
|
||||||
|
|
||||||
if (expires == NULL) {
|
e = r->headers_out.expires;
|
||||||
|
|
||||||
expires = ngx_list_push(&r->headers_out.headers);
|
if (e == NULL) {
|
||||||
if (expires == NULL) {
|
|
||||||
|
e = ngx_list_push(&r->headers_out.headers);
|
||||||
|
if (e == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
r->headers_out.expires = expires;
|
r->headers_out.expires = e;
|
||||||
|
|
||||||
expires->hash = 1;
|
e->hash = 1;
|
||||||
ngx_str_set(&expires->key, "Expires");
|
ngx_str_set(&e->key, "Expires");
|
||||||
}
|
}
|
||||||
|
|
||||||
len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
|
len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
|
||||||
expires->value.len = len - 1;
|
e->value.len = len - 1;
|
||||||
|
|
||||||
ccp = r->headers_out.cache_control.elts;
|
ccp = r->headers_out.cache_control.elts;
|
||||||
|
|
||||||
@ -265,26 +269,26 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
|
|||||||
cc = ccp[0];
|
cc = ccp[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf->expires == NGX_HTTP_EXPIRES_EPOCH) {
|
if (expires == NGX_HTTP_EXPIRES_EPOCH) {
|
||||||
expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
|
e->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
|
||||||
ngx_str_set(&cc->value, "no-cache");
|
ngx_str_set(&cc->value, "no-cache");
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf->expires == NGX_HTTP_EXPIRES_MAX) {
|
if (expires == NGX_HTTP_EXPIRES_MAX) {
|
||||||
expires->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
|
e->value.data = (u_char *) "Thu, 31 Dec 2037 23:55:55 GMT";
|
||||||
/* 10 years */
|
/* 10 years */
|
||||||
ngx_str_set(&cc->value, "max-age=315360000");
|
ngx_str_set(&cc->value, "max-age=315360000");
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
expires->value.data = ngx_pnalloc(r->pool, len);
|
e->value.data = ngx_pnalloc(r->pool, len);
|
||||||
if (expires->value.data == NULL) {
|
if (e->value.data == NULL) {
|
||||||
return NGX_ERROR;
|
return NGX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conf->expires_time == 0 && conf->expires != NGX_HTTP_EXPIRES_DAILY) {
|
if (expires_time == 0 && expires != NGX_HTTP_EXPIRES_DAILY) {
|
||||||
ngx_memcpy(expires->value.data, ngx_cached_http_time.data,
|
ngx_memcpy(e->value.data, ngx_cached_http_time.data,
|
||||||
ngx_cached_http_time.len + 1);
|
ngx_cached_http_time.len + 1);
|
||||||
ngx_str_set(&cc->value, "max-age=0");
|
ngx_str_set(&cc->value, "max-age=0");
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
@ -292,22 +296,22 @@ ngx_http_set_expires(ngx_http_request_t *r, ngx_http_headers_conf_t *conf)
|
|||||||
|
|
||||||
now = ngx_time();
|
now = ngx_time();
|
||||||
|
|
||||||
if (conf->expires == NGX_HTTP_EXPIRES_DAILY) {
|
if (expires == NGX_HTTP_EXPIRES_DAILY) {
|
||||||
expires_time = ngx_next_time(conf->expires_time);
|
expires_time = ngx_next_time(expires_time);
|
||||||
max_age = expires_time - now;
|
max_age = expires_time - now;
|
||||||
|
|
||||||
} else if (conf->expires == NGX_HTTP_EXPIRES_ACCESS
|
} else if (expires == NGX_HTTP_EXPIRES_ACCESS
|
||||||
|| r->headers_out.last_modified_time == -1)
|
|| r->headers_out.last_modified_time == -1)
|
||||||
{
|
{
|
||||||
expires_time = now + conf->expires_time;
|
max_age = expires_time;
|
||||||
max_age = conf->expires_time;
|
expires_time += now;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
expires_time = r->headers_out.last_modified_time + conf->expires_time;
|
expires_time += r->headers_out.last_modified_time;
|
||||||
max_age = expires_time - now;
|
max_age = expires_time - now;
|
||||||
}
|
}
|
||||||
|
|
||||||
ngx_http_time(expires->value.data, expires_time);
|
ngx_http_time(e->value.data, expires_time);
|
||||||
|
|
||||||
if (conf->expires_time < 0 || max_age < 0) {
|
if (conf->expires_time < 0 || max_age < 0) {
|
||||||
ngx_str_set(&cc->value, "no-cache");
|
ngx_str_set(&cc->value, "no-cache");
|
||||||
|
Loading…
Reference in New Issue
Block a user