diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 3b410ff..66c1e65 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -296,7 +296,9 @@ define nginx::resource::location ( validate_string($proxy_cache_use_stale) } if ($proxy_cache_valid != false) { - validate_string($proxy_cache_valid) + if !(is_array($proxy_cache_valid) or is_string($proxy_cache_valid)) { + fail('$proxy_cache_valid must be a string or an array or false.') + } } if ($proxy_method != undef) { validate_string($proxy_method) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 69c71ef..ad37a09 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -377,7 +377,9 @@ define nginx::resource::vhost ( validate_string($proxy_cache_use_stale) } if ($proxy_cache_valid != false) { - validate_string($proxy_cache_valid) + if !(is_array($proxy_cache_valid) or is_string($proxy_cache_valid)) { + fail('$proxy_cache_valid must be a string or an array or false.') + } } if ($proxy_method != undef) { validate_string($proxy_method) diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index bdb1243..30e102e 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -599,11 +599,20 @@ describe 'nginx::resource::location' do :notmatch => /proxy_cache_valid\b/ }, { - :title => 'should set proxy_cache_valid', + :title => 'should set proxy_cache_valid when string', :attr => 'proxy_cache_valid', :value => 'value', :match => /^\s+proxy_cache_valid\s+value;/, }, + { + :title => 'should set proxy_cache_valid when array of strings', + :attr => 'proxy_cache_valid', + :value => ['value1','value2'], + :match => [ + /^\s+proxy_cache_valid\s+value1;/, + /^\s+proxy_cache_valid\s+value2;/, + ] + }, { :title => 'should not set proxy_cache', :attr => 'proxy_cache', diff --git a/templates/vhost/locations/proxy.erb b/templates/vhost/locations/proxy.erb index 15a3f72..73d42bb 100644 --- a/templates/vhost/locations/proxy.erb +++ b/templates/vhost/locations/proxy.erb @@ -16,8 +16,10 @@ <% if @proxy_cache -%> proxy_cache <%= @proxy_cache %>; <% end -%> -<% if @proxy_cache_valid -%> - proxy_cache_valid <%= @proxy_cache_valid %>; +<% if @proxy_cache_valid && Array(@proxy_cache_valid).size > 0 -%> + <%- Array(@proxy_cache_valid).each do |line| -%> + proxy_cache_valid <%= line %>; + <%- end -%> <% end -%> <% if @proxy_cache_use_stale -%> proxy_cache_use_stale <%= @proxy_cache_use_stale %>;