Allow multiple 'proxy_cache_valid' directives

This commit is contained in:
herwig Bogaert 2016-03-25 11:14:29 +00:00
parent 56e1c591bf
commit 40d157482e
4 changed files with 16 additions and 5 deletions

View file

@ -296,7 +296,7 @@ define nginx::resource::location (
validate_string($proxy_cache_use_stale) validate_string($proxy_cache_use_stale)
} }
if ($proxy_cache_valid != false) { if ($proxy_cache_valid != false) {
validate_string($proxy_cache_valid) validate_slength(any2array($proxy_cache_valid),12,1)
} }
if ($proxy_method != undef) { if ($proxy_method != undef) {
validate_string($proxy_method) validate_string($proxy_method)

View file

@ -372,7 +372,7 @@ define nginx::resource::vhost (
validate_string($proxy_cache_use_stale) validate_string($proxy_cache_use_stale)
} }
if ($proxy_cache_valid != false) { if ($proxy_cache_valid != false) {
validate_string($proxy_cache_valid) validate_slength(any2array($proxy_cache_valid),12,1)
} }
if ($proxy_method != undef) { if ($proxy_method != undef) {
validate_string($proxy_method) validate_string($proxy_method)

View file

@ -599,11 +599,20 @@ describe 'nginx::resource::location' do
:notmatch => /proxy_cache_valid\b/ :notmatch => /proxy_cache_valid\b/
}, },
{ {
:title => 'should set proxy_cache_valid', :title => 'should set proxy_cache_valid when string',
:attr => 'proxy_cache_valid', :attr => 'proxy_cache_valid',
:value => 'value', :value => 'value',
:match => /^\s+proxy_cache_valid\s+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', :title => 'should not set proxy_cache',
:attr => 'proxy_cache', :attr => 'proxy_cache',

View file

@ -16,8 +16,10 @@
<% if @proxy_cache -%> <% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>; proxy_cache <%= @proxy_cache %>;
<% end -%> <% end -%>
<% if @proxy_cache_valid -%> <% if @proxy_cache_valid && Array(@proxy_cache_valid).size > 0 -%>
proxy_cache_valid <%= @proxy_cache_valid %>; <%- Array(@proxy_cache_valid).each do |line| -%>
proxy_cache_valid <%= line %>;
<%- end -%>
<% end -%> <% end -%>
<% if @proxy_cache_use_stale -%> <% if @proxy_cache_use_stale -%>
proxy_cache_use_stale <%= @proxy_cache_use_stale %>; proxy_cache_use_stale <%= @proxy_cache_use_stale %>;