Welcome! Log In Create A New Profile

Advanced

Patch for Age header

Woon Wai Keen
June 09, 2010 01:50AM
Hi all, I would like to contribute a patch to provide the cached file
age as a variable $proxy_cache_age , which can then be used together
with add_header Age $proxy_cache_age.

The age calculation is not RFC2616 compliant (13.2.3) as it doesn't take
into consideration the cached origin Age header and Date. Is it feasible
to extract this from the cached headers?

--
regards,
wK

Index: http/modules/ngx_http_proxy_module.c
===================================================================
--- http/modules/ngx_http_proxy_module.c (revision 405)
+++ http/modules/ngx_http_proxy_module.c (working copy)
@@ -117,6 +117,9 @@
static ngx_int_t
ngx_http_proxy_internal_body_length_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t
+ ngx_http_proxy_cache_age_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_proxy_rewrite_redirect(ngx_http_request_t *r,
ngx_table_elt_t *h, size_t prefix);

@@ -580,6 +583,11 @@
{ ngx_string("proxy_internal_body_length"), NULL,
ngx_http_proxy_internal_body_length_variable, 0, NGX_HTTP_VAR_NOHASH, 0 },

+#if (NGX_HTTP_CACHE)
+ { ngx_string("proxy_cache_age"), NULL,
+ ngx_http_proxy_cache_age_variable, 0, NGX_HTTP_VAR_NOHASH, 0 },
+#endif
+
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};

@@ -3052,3 +3060,33 @@

v->uri = u->uri;
}
+
+#if (NGX_HTTP_CACHE)
+static ngx_int_t
+ngx_http_proxy_cache_age_variable(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ ngx_int_t age;
+
+ if (r->cache == NULL || r->cache->date == 0) {
+ v->not_found = 1;
+ return NGX_OK;
+ }
+
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+
+ v->data = ngx_pnalloc(r->connection->pool, NGX_TIME_T_LEN);
+
+ if (v->data == NULL) {
+ return NGX_ERROR;
+ }
+
+ age = r->start_sec - r->cache->date;
+ v->len = ngx_sprintf(v->data, "%T", age) - v->data;
+
+ return NGX_OK;
+}
+
+#endif
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Patch for Age header

Woon Wai Keen 2585 June 09, 2010 01:50AM

Re: Patch for Age header

Woon Wai Keen 792 September 22, 2011 05:12PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 228
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready