summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_upstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/ngx_http_upstream.c')
-rw-r--r--src/http/ngx_http_upstream.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 4e71af010..c9a998001 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -13,6 +13,8 @@
#if (NGX_HTTP_CACHE)
static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r,
ngx_http_upstream_t *u);
+static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r,
+ ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
@@ -723,8 +725,9 @@ found:
static ngx_int_t
ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
- ngx_int_t rc;
- ngx_http_cache_t *c;
+ ngx_int_t rc;
+ ngx_http_cache_t *c;
+ ngx_http_file_cache_t *cache;
c = r->cache;
@@ -734,6 +737,12 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
return NGX_DECLINED;
}
+ rc = ngx_http_upstream_cache_get(r, u, &cache);
+
+ if (rc != NGX_OK) {
+ return rc;
+ }
+
if (r->method & NGX_HTTP_HEAD) {
u->method = ngx_http_core_get_method;
}
@@ -767,7 +776,7 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
c->body_start = u->conf->buffer_size;
c->min_uses = u->conf->cache_min_uses;
- c->file_cache = u->conf->cache_zone->data;
+ c->file_cache = cache;
switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {
@@ -874,6 +883,49 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
static ngx_int_t
+ngx_http_upstream_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u,
+ ngx_http_file_cache_t **cache)
+{
+ ngx_str_t *name, val;
+ ngx_uint_t i;
+ ngx_http_file_cache_t **caches;
+
+ if (u->conf->cache_zone) {
+ *cache = u->conf->cache_zone->data;
+ return NGX_OK;
+ }
+
+ if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) {
+ return NGX_ERROR;
+ }
+
+ if (val.len == 0
+ || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0))
+ {
+ return NGX_DECLINED;
+ }
+
+ caches = u->caches->elts;
+
+ for (i = 0; i < u->caches->nelts; i++) {
+ name = &caches[i]->shm_zone->shm.name;
+
+ if (name->len == val.len
+ && ngx_strncmp(name->data, val.data, val.len) == 0)
+ {
+ *cache = caches[i];
+ return NGX_OK;
+ }
+ }
+
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "cache \"%V\" not found", &val);
+
+ return NGX_ERROR;
+}
+
+
+static ngx_int_t
ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
ngx_int_t rc;