Klaus Demo nginx / 1839e0d
merge r3518, r3527: cache related fixes: *) do not cache response if it has "no-store" or "private" in "Cache-Control" header *) proxy_no_cache and fastcgi_no_cache Igor Sysoev 12 years ago
6 changed file(s) with 108 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
331331 0,
332332 0,
333333 &ngx_http_fastcgi_module },
334
335 { ngx_string("fastcgi_no_cache"),
336 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
337 ngx_http_no_cache_set_slot,
338 NGX_HTTP_LOC_CONF_OFFSET,
339 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.no_cache),
340 NULL },
334341
335342 { ngx_string("fastcgi_cache_valid"),
336343 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
18891896 #if (NGX_HTTP_CACHE)
18901897 conf->upstream.cache = NGX_CONF_UNSET_PTR;
18911898 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
1899 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
18921900 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
18931901 #endif
18941902
21102118
21112119 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD;
21122120
2121 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
2122 prev->upstream.no_cache, NULL);
2123
21132124 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
21142125 prev->upstream.cache_valid, NULL);
21152126
355355 0,
356356 0,
357357 &ngx_http_proxy_module },
358
359 { ngx_string("proxy_no_cache"),
360 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
361 ngx_http_no_cache_set_slot,
362 NGX_HTTP_LOC_CONF_OFFSET,
363 offsetof(ngx_http_proxy_loc_conf_t, upstream.no_cache),
364 NULL },
358365
359366 { ngx_string("proxy_cache_valid"),
360367 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
19321939 #if (NGX_HTTP_CACHE)
19331940 conf->upstream.cache = NGX_CONF_UNSET_PTR;
19341941 conf->upstream.cache_min_uses = NGX_CONF_UNSET_UINT;
1942 conf->upstream.no_cache = NGX_CONF_UNSET_PTR;
19351943 conf->upstream.cache_valid = NGX_CONF_UNSET_PTR;
19361944 #endif
19371945
21552163 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET
21562164 |NGX_HTTP_UPSTREAM_FT_OFF;
21572165 }
2166
2167 ngx_conf_merge_ptr_value(conf->upstream.no_cache,
2168 prev->upstream.no_cache, NULL);
21582169
21592170 ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
21602171 prev->upstream.cache_valid, NULL);
132132 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
133133 void *conf);
134134
135 ngx_int_t ngx_http_cache(ngx_http_request_t *r, ngx_array_t *no_cache);
136 char *ngx_http_no_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
137 void *conf);
138
139
135140 extern ngx_str_t ngx_http_cache_status[];
136141
137142
16031603
16041604 return NGX_CONF_OK;
16051605 }
1606
1607
1608 ngx_int_t
1609 ngx_http_cache(ngx_http_request_t *r, ngx_array_t *no_cache)
1610 {
1611 ngx_str_t val;
1612 ngx_uint_t i;
1613 ngx_http_complex_value_t *cv;
1614
1615 cv = no_cache->elts;
1616
1617 for (i = 0; i < no_cache->nelts; i++) {
1618 if (ngx_http_complex_value(r, &cv[i], &val) != NGX_OK) {
1619 return NGX_ERROR;
1620 }
1621
1622 if (val.len && val.data[0] != '0') {
1623 return NGX_DECLINED;
1624 }
1625 }
1626
1627 return NGX_OK;
1628 }
1629
1630
1631 char *
1632 ngx_http_no_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1633 {
1634 char *p = conf;
1635
1636 ngx_str_t *value;
1637 ngx_uint_t i;
1638 ngx_array_t **a;
1639 ngx_http_complex_value_t *cv;
1640 ngx_http_compile_complex_value_t ccv;
1641
1642 a = (ngx_array_t **) (p + cmd->offset);
1643
1644 if (*a == NGX_CONF_UNSET_PTR) {
1645 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_complex_value_t));
1646 if (*a == NULL) {
1647 return NGX_CONF_ERROR;
1648 }
1649 }
1650
1651 value = cf->args->elts;
1652
1653 for (i = 1; i < cf->args->nelts; i++) {
1654 cv = ngx_array_push(*a);
1655 if (cv == NULL) {
1656 return NGX_CONF_ERROR;
1657 }
1658
1659 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1660
1661 ccv.cf = cf;
1662 ccv.value = &value[i];
1663 ccv.complex_value = cv;
1664
1665 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1666 return NGX_CONF_ERROR;
1667 }
1668 }
1669
1670 return NGX_CONF_OK;
1671 }
584584 ngx_int_t rc;
585585 ngx_http_cache_t *c;
586586
587 if (u->conf->no_cache) {
588 rc = ngx_http_cache(r, u->conf->no_cache);
589 if (rc != NGX_OK) {
590 return rc;
591 }
592 }
593
587594 if (!(r->method & u->conf->cache_methods)) {
588595 return NGX_DECLINED;
589596 }
30013008 return NGX_OK;
30023009 }
30033010
3004 last = h->value.data + h->value.len;
3005
3006 if (ngx_strlcasestrn(h->value.data, last, (u_char *) "no-cache", 8 - 1)
3007 != NULL)
3011 p = h->value.data;
3012 last = p + h->value.len;
3013
3014 if (ngx_strlcasestrn(p, last, (u_char *) "no-cache", 8 - 1) != NULL
3015 || ngx_strlcasestrn(p, last, (u_char *) "no-store", 8 - 1) != NULL
3016 || ngx_strlcasestrn(p, last, (u_char *) "private", 7 - 1) != NULL)
30083017 {
30093018 u->cacheable = 0;
30103019 return NGX_OK;
30113020 }
30123021
3013 p = ngx_strlcasestrn(h->value.data, last, (u_char *) "max-age=", 8 - 1);
3022 p = ngx_strlcasestrn(p, last, (u_char *) "max-age=", 8 - 1);
30143023
30153024 if (p == NULL) {
30163025 return NGX_OK;
159159 ngx_uint_t cache_methods;
160160
161161 ngx_array_t *cache_valid;
162 ngx_array_t *no_cache; /* ngx_http_complex_value_t */
162163 #endif
163164
164165 ngx_array_t *store_lengths;