Mercurial > hg > nginx
changeset 9276:5e7588d2d9cc
Upstream: $upstream_cache_key variable.
author | Kirill A. Korinsky <kirill@korins.ky> |
---|---|
date | Thu, 23 May 2024 18:48:32 +0300 |
parents | 199dc0d6b05b |
children | 4a0cd107c0f1 |
files | src/http/ngx_http_upstream.c |
diffstat | 1 files changed, 49 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c Fri May 24 00:20:01 2024 +0300 +++ b/src/http/ngx_http_upstream.c Thu May 23 18:48:32 2024 +0300 @@ -23,6 +23,8 @@ ngx_http_upstream_t *u); static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); +static ngx_int_t ngx_http_upstream_cache_key(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_upstream_cache_etag(ngx_http_request_t *r, @@ -414,6 +416,10 @@ ngx_http_upstream_cache_status, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, + { ngx_string("upstream_cache_key"), NULL, + ngx_http_upstream_cache_key, 0, + NGX_HTTP_VAR_NOCACHEABLE, 0 }, + { ngx_string("upstream_cache_last_modified"), NULL, ngx_http_upstream_cache_last_modified, 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 }, @@ -6004,6 +6010,49 @@ static ngx_int_t +ngx_http_upstream_cache_key(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data) +{ + u_char *p; + size_t len; + ngx_str_t *key; + ngx_uint_t i; + ngx_http_cache_t *c; + + if (r->cache == NULL || r->cache->keys.nelts == 0) { + v->not_found = 1; + return NGX_OK; + } + + c = r->cache; + + len = 0; + key = c->keys.elts; + + for (i = 0; i < c->keys.nelts; i++) { + len += key[i].len; + } + + p = ngx_pnalloc(r->pool, len); + if (p == NULL) { + return NGX_ERROR; + } + + v->len = len; + v->valid = 1; + v->no_cacheable = 0; + v->not_found = 0; + v->data = p; + + for (i = 0; i < c->keys.nelts; i++) { + p = ngx_cpymem(p, key[i].data, key[i].len); + } + + return NGX_OK; +} + + +static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {