Skip to content

Commit

Permalink
Upstream: proxy_cache_convert_head directive.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
arut committed Nov 11, 2015
1 parent 93aef08 commit 89a049b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/http/modules/ngx_http_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ static ngx_command_t ngx_http_proxy_commands[] = {
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"),
Expand Down Expand Up @@ -2845,6 +2852,7 @@ ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
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;
Expand Down Expand Up @@ -3143,6 +3151,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
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, "");
Expand Down
2 changes: 1 addition & 1 deletion src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
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;
}

Expand Down
1 change: 1 addition & 0 deletions src/http/ngx_http_upstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 89a049b

Please sign in to comment.