[nginx] Upstream: $upstream_cache_key variable.
Maxim Dounin
mdounin at mdounin.ru
Fri May 24 00:54:13 UTC 2024
details: http://freenginx.org/hg/nginx/rev/5e7588d2d9cc
branches:
changeset: 9276:5e7588d2d9cc
user: Kirill A. Korinsky <kirill at korins.ky>
date: Thu May 23 18:48:32 2024 +0300
description:
Upstream: $upstream_cache_key variable.
diffstat:
src/http/ngx_http_upstream.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 0 deletions(-)
diffs (73 lines):
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -23,6 +23,8 @@ static ngx_int_t ngx_http_upstream_cache
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 @@ static ngx_http_variable_t ngx_http_ups
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 @@ ngx_http_upstream_cache_status(ngx_http_
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)
{
More information about the nginx-devel
mailing list