Welcome! Log In Create A New Profile

Advanced

[nginx] Upstream: proxy_cache_convert_head directive.

Roman Arutyunyan
November 11, 2015 07:56AM
details: http://hg.nginx.org/nginx/rev/4d5ac1a31d44
branches:
changeset: 6290:4d5ac1a31d44
user: Roman Arutyunyan <arut@nginx.com>
date: Wed Nov 11 15:47:30 2015 +0300
description:
Upstream: proxy_cache_convert_head directive.

The directive toggles conversion of HEAD to GET for cacheable proxy requests.
When disabled, $request_method must be added to cache key for consistency.
By default, HEAD is converted to GET as before.

diffstat:

src/http/modules/ngx_http_proxy_module.c | 11 +++++++++++
src/http/ngx_http_upstream.c | 2 +-
src/http/ngx_http_upstream.h | 1 +
3 files changed, 13 insertions(+), 1 deletions(-)

diffs (58 lines):

diff -r 909b5b191f25 -r 4d5ac1a31d44 src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c Thu Nov 05 15:01:09 2015 +0300
+++ b/src/http/modules/ngx_http_proxy_module.c Wed Nov 11 15:47:30 2015 +0300
@@ -533,6 +533,13 @@ static ngx_command_t ngx_http_proxy_com
offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_revalidate),
NULL },

+ { ngx_string("proxy_cache_convert_head"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
+ ngx_conf_set_flag_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_proxy_loc_conf_t, upstream.cache_convert_head),
+ NULL },
+
#endif

{ ngx_string("proxy_temp_path"),
@@ -2845,6 +2852,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_
conf->upstream.cache_lock_timeout = NGX_CONF_UNSET_MSEC;
conf->upstream.cache_lock_age = NGX_CONF_UNSET_MSEC;
conf->upstream.cache_revalidate = NGX_CONF_UNSET;
+ conf->upstream.cache_convert_head = NGX_CONF_UNSET;
#endif

conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;
@@ -3143,6 +3151,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
ngx_conf_merge_value(conf->upstream.cache_revalidate,
prev->upstream.cache_revalidate, 0);

+ ngx_conf_merge_value(conf->upstream.cache_convert_head,
+ prev->upstream.cache_convert_head, 1);
+
#endif

ngx_conf_merge_str_value(conf->method, prev->method, "");
diff -r 909b5b191f25 -r 4d5ac1a31d44 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c Thu Nov 05 15:01:09 2015 +0300
+++ b/src/http/ngx_http_upstream.c Wed Nov 11 15:47:30 2015 +0300
@@ -764,7 +764,7 @@ ngx_http_upstream_cache(ngx_http_request
return rc;
}

- if (r->method & NGX_HTTP_HEAD) {
+ if ((r->method & NGX_HTTP_HEAD) && u->conf->cache_convert_head) {
u->method = ngx_http_core_get_method;
}

diff -r 909b5b191f25 -r 4d5ac1a31d44 src/http/ngx_http_upstream.h
--- a/src/http/ngx_http_upstream.h Thu Nov 05 15:01:09 2015 +0300
+++ b/src/http/ngx_http_upstream.h Wed Nov 11 15:47:30 2015 +0300
@@ -193,6 +193,7 @@ typedef struct {
ngx_msec_t cache_lock_age;

ngx_flag_t cache_revalidate;
+ ngx_flag_t cache_convert_head;

ngx_array_t *cache_valid;
ngx_array_t *cache_bypass;

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream: proxy_cache_convert_head directive.

Roman Arutyunyan 664 November 11, 2015 07:56AM



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

Online Users

Guests: 313
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