aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/proxy/ngx_http_proxy_cache.c
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2003-11-03 22:20:44 +0000
committerIgor Sysoev <igor@sysoev.ru>2003-11-03 22:20:44 +0000
commitcf80a70e1030f3c12e9b19e34e4f9ee9e2f72629 (patch)
tree0611cee87cc3d27340cff7fc8d324f6f61ad56b7 /src/http/modules/proxy/ngx_http_proxy_cache.c
parenta1512b1904fc7e3a0a5b99e49cff480085518445 (diff)
downloadnginx-cf80a70e1030f3c12e9b19e34e4f9ee9e2f72629.tar.gz
nginx-cf80a70e1030f3c12e9b19e34e4f9ee9e2f72629.zip
nginx-0.0.1-2003-11-04-01:20:44 import
Diffstat (limited to 'src/http/modules/proxy/ngx_http_proxy_cache.c')
-rw-r--r--src/http/modules/proxy/ngx_http_proxy_cache.c115
1 files changed, 113 insertions, 2 deletions
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index 6309b398d..b01e5871f 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -56,11 +56,29 @@ int ngx_http_proxy_get_cached_response(ngx_http_proxy_ctx_t *p)
rc = ngx_http_cache_get_file(r, &c->ctx);
- if (rc == NGX_STALE) {
+ switch (rc) {
+ case NGX_HTTP_CACHE_STALE:
p->stale = 1;
+ p->state->cache = NGX_HTTP_PROXY_CACHE_EXPR;
+ break;
+
+ case NGX_HTTP_CACHE_AGED:
+ p->stale = 1;
+ p->state->cache = NGX_HTTP_PROXY_CACHE_AGED;
+ break;
+
+ case NGX_OK:
+ p->state->cache = NGX_HTTP_PROXY_CACHE_HIT;
+ break;
+
+ default:
+ p->state->cache = NGX_HTTP_PROXY_CACHE_MISS;
}
- if (rc == NGX_OK || rc == NGX_STALE) {
+ if (rc == NGX_OK
+ || rc == NGX_HTTP_CACHE_STALE
+ || rc == NGX_HTTP_CACHE_AGED)
+ {
p->header_in->pos += c->ctx.header_size;
if (ngx_http_proxy_process_cached_header(p) == NGX_ERROR) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -246,6 +264,99 @@ int ngx_http_proxy_send_cached_response(ngx_http_proxy_ctx_t *p)
}
+int ngx_http_proxy_is_cachable(ngx_http_proxy_ctx_t *p)
+{
+ time_t date, last_modified, expires;
+ ngx_http_proxy_headers_in_t *h;
+
+ switch (p->upstream->status) {
+ case NGX_HTTP_OK:
+ case NGX_HTTP_MOVED_PERMANENTLY:
+ case NGX_HTTP_MOVED_TEMPORARILY:
+ break;
+
+#if 0
+ case NGX_HTTP_NOT_MODIFIED:
+ return 1;
+#endif
+
+ default:
+ return 0;
+ }
+
+ h = &p->upstream->headers_in;
+
+ date = NGX_ERROR;
+ if (h->date) {
+ date = ngx_http_parse_time(h->date->value.data, h->date->value.len);
+ }
+ if (date == NGX_ERROR) {
+ date = ngx_time();
+ }
+ p->cache->ctx.header.date = date;
+
+ last_modified = NGX_ERROR;
+ if (h->last_modified) {
+ last_modified = ngx_http_parse_time(h->last_modified->value.data,
+ h->last_modified->value.len);
+ p->cache->ctx.header.last_modified = last_modified;
+ }
+
+ if (h->x_accel_expires) {
+ expires = ngx_atoi(h->x_accel_expires->value.data,
+ h->x_accel_expires->value.len);
+ if (expires != NGX_ERROR) {
+ p->state->reason = NGX_HTTP_PROXY_CACHE_XAE;
+ p->cache->ctx.header.expires = date + expires;
+ return (expires > 0);
+ }
+ }
+
+ if (!p->lcf->ignore_expires) {
+
+ /* TODO: Cache-Control: no-cache, max-age= */
+
+ if (h->expires) {
+ expires = ngx_http_parse_time(h->expires->value.data,
+ h->expires->value.len);
+ if (expires != NGX_ERROR) {
+ p->state->reason = NGX_HTTP_PROXY_CACHE_EXP;
+ p->cache->ctx.header.expires = expires;
+ return (date < expires);
+ }
+ }
+ }
+
+ if (p->upstream->status == NGX_HTTP_MOVED_PERMANENTLY) {
+ p->state->reason = NGX_HTTP_PROXY_CACHE_MVD;
+ p->cache->ctx.header.expires = /* STUB: 1 hour */ 60 * 60;
+ return 1;
+ }
+
+ if (p->upstream->status == NGX_HTTP_MOVED_TEMPORARILY) {
+ return 1;
+ }
+
+ if (last_modified != NGX_ERROR && p->lcf->lm_factor > 0) {
+
+ /* FIXME: time_t == int_64_t */
+
+ p->state->reason = NGX_HTTP_PROXY_CACHE_LMF;
+ p->cache->ctx.header.expires = ngx_time()
+ + (((int64_t) (date - last_modified)) * p->lcf->lm_factor) / 100;
+ return 1;
+ }
+
+ if (p->lcf->default_expires > 0) {
+ p->state->reason = NGX_HTTP_PROXY_CACHE_PDE;
+ p->cache->ctx.header.expires = p->lcf->default_expires;
+ return 1;
+ }
+
+ return 0;
+}
+
+
int ngx_http_proxy_update_cache(ngx_http_proxy_ctx_t *p)
{
if (p->cache == NULL) {