From 66524e22b47aca669e89f4cd4844c9e46cc41620 Mon Sep 17 00:00:00 2001 From: Jacob McCoy Wade Date: Fri, 29 May 2015 14:21:34 -0700 Subject: [PATCH] Adding ability to add proxy_cache_use_stale and proxy_cache_key within a location resource Adding spec tests for proxy_cache_key and proxy_cache_use_stale --- manifests/resource/location.pp | 12 ++++++++++++ manifests/resource/vhost.pp | 14 ++++++++++++++ spec/defines/resource_location_spec.rb | 14 +++++++++++++- templates/vhost/locations/proxy.erb | 6 ++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 3b5313a72..6c8f3607a 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -70,6 +70,10 @@ # [*option*] - Reserved for future use # [*proxy_cache*] - This directive sets name of zone for caching. # The same zone can be used in multiple places. +# [*proxy_cache_key*] - Override the default proxy_cache_key of +# $scheme$proxy_host$request_uri +# [*proxy_cache_use_stale*] - Override the default proxy_cache_use_stale value +# of off. # [*proxy_cache_valid*] - This directive sets the time for caching # different replies. # [*proxy_method*] - If defined, overrides the HTTP method of the @@ -166,6 +170,8 @@ $include = undef, $try_files = undef, $proxy_cache = false, + $proxy_cache_key = undef, + $proxy_cache_use_stale = undef, $proxy_cache_valid = false, $proxy_method = undef, $proxy_set_body = undef, @@ -277,6 +283,12 @@ if ($proxy_cache != false) { validate_string($proxy_cache) } + if ($proxy_cache_key != undef) { + validate_string($proxy_cache_key) + } + if ($proxy_cache_use_stale != undef) { + validate_string($proxy_cache_use_stale) + } if ($proxy_cache_valid != false) { validate_string($proxy_cache_valid) } diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 8e9a94cc8..95a55f53d 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -85,6 +85,10 @@ # checked as an array. Cannot be used in conjuction with $proxy. # [*proxy_cache*] - This directive sets name of zone for caching. # The same zone can be used in multiple places. +# [*proxy_cache_key*] - Override the default proxy_cache_key of +# $scheme$proxy_host$request_uri +# [*proxy_cache_use_stale*] - Override the default proxy_cache_use_stale value +# of off. # [*proxy_cache_valid*] - This directive sets the time for caching # different replies. # [*proxy_method*] - If defined, overrides the HTTP method of the @@ -193,6 +197,8 @@ $proxy_connect_timeout = $::nginx::config::proxy_connect_timeout, $proxy_set_header = [], $proxy_cache = false, + $proxy_cache_key = undef, + $proxy_cache_use_stale = undef, $proxy_cache_valid = false, $proxy_method = undef, $proxy_set_body = undef, @@ -322,6 +328,12 @@ if ($proxy_cache != false) { validate_string($proxy_cache) } + if ($proxy_cache_key != undef) { + validate_string($proxy_cache_key) + } + if ($proxy_cache_use_stale != undef) { + validate_string($proxy_cache_use_stale) + } if ($proxy_cache_valid != false) { validate_string($proxy_cache_valid) } @@ -530,6 +542,8 @@ proxy_read_timeout => $proxy_read_timeout, proxy_connect_timeout => $proxy_connect_timeout, proxy_cache => $proxy_cache, + proxy_cache_key => $proxy_cache_key, + proxy_cache_use_stale => $proxy_cache_use_stale, proxy_cache_valid => $proxy_cache_valid, proxy_method => $proxy_method, proxy_set_header => $proxy_set_header, diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 20a246dc0..7f550808c 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -604,7 +604,19 @@ :value => false, :notmatch => /proxy_cache\b/ }, - { + { + :title => 'should set proxy_cache_key', + :attr => 'proxy_cache_key', + :value => 'value', + :match => /^\s+proxy_cache_key\s+value;/, + }, + { + :title => 'should set proxy_cache_use_stale', + :attr => 'proxy_cache_use_stale', + :value => 'value', + :match => /^\s+proxy_cache_use_stale\s+value;/ + }, + { :title => 'should set proxy_pass', :attr => 'proxy', :value => 'value', diff --git a/templates/vhost/locations/proxy.erb b/templates/vhost/locations/proxy.erb index 1687417bf..237dac4fe 100644 --- a/templates/vhost/locations/proxy.erb +++ b/templates/vhost/locations/proxy.erb @@ -21,3 +21,9 @@ <% if @proxy_cache_valid -%> proxy_cache_valid <%= @proxy_cache_valid %>; <% end -%> +<% if @proxy_cache_use_stale -%> + proxy_cache_use_stale <%= @proxy_cache_use_stale %>; +<% end -%> +<% if @proxy_cache_key -%> + proxy_cache_key <%= @proxy_cache_key %>; +<% end -%>