Skip to content

Commit

Permalink
adding support for proxy_cache_bypass and proxy_cache_lock (voxpupuli…
Browse files Browse the repository at this point in the history
…#1150)

* adding support for proxy_cache_bypass and proxy_cache_lock

* adding tests and restrict proxy_cache_lock to enum
  • Loading branch information
ceonizm committed Feb 6, 2020
1 parent ed8c3f0 commit 7783735
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
4 changes: 4 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
# of off.
# [*proxy_cache_valid*] - This directive sets the time for caching
# different replies.
# [*proxy_cache_lock*] - This directive sets the locking mechanism for pouplating cache.
# [*proxy_cache_bypass*] - Defines conditions which the response will not be cached
# [*proxy_method*] - If defined, overrides the HTTP method of the
# request to be passed to the backend.
# [*proxy_http_version*] - Sets the proxy http version
Expand Down Expand Up @@ -201,6 +203,8 @@
Optional[String] $proxy_cache = undef,
Optional[String] $proxy_cache_key = undef,
Optional[String] $proxy_cache_use_stale = undef,
Optional[Enum['on', 'off']] $proxy_cache_lock = undef,
Optional[Variant[Array, String]] $proxy_cache_bypass = undef,
Optional[Variant[Array, String]] $proxy_cache_valid = undef,
Optional[String] $proxy_method = undef,
Optional[String] $proxy_http_version = undef,
Expand Down
6 changes: 6 additions & 0 deletions manifests/resource/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
# [*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_cache_lock*] - This directive sets the locking mechanism for pouplating cache.
# [*proxy_cache_bypass*] - Defines conditions which the response will not be cached
# [*proxy_method*] - If defined, overrides the HTTP method of the request to be passed to the backend.
# [*proxy_http_version*] - Sets the proxy http version
# [*proxy_set_body*] - If defined, sets the body passed to the backend.
Expand Down Expand Up @@ -187,6 +189,8 @@
Optional[String] $proxy_cache_key = undef,
Optional[String] $proxy_cache_use_stale = undef,
Optional[Variant[Array[String], String]] $proxy_cache_valid = undef,
Optional[Enum['on', 'off']] $proxy_cache_lock = undef,
Optional[Variant[Array[String], String]] $proxy_cache_bypass = undef,
Optional[String] $proxy_method = undef,
Optional[String] $proxy_http_version = undef,
Optional[String] $proxy_set_body = undef,
Expand Down Expand Up @@ -354,7 +358,9 @@
proxy_set_header => $proxy_set_header,
proxy_hide_header => $proxy_hide_header,
proxy_pass_header => $proxy_pass_header,
proxy_cache_lock => $proxy_cache_lock,
proxy_set_body => $proxy_set_body,
proxy_cache_bypass => $proxy_cache_bypass,
proxy_buffering => $proxy_buffering,
fastcgi => $fastcgi,
fastcgi_index => $fastcgi_index,
Expand Down
30 changes: 30 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,36 @@
value: 'value',
match: %r{^\s+proxy_cache_use_stale\s+value;}
},
{
title: 'should set proxy_cache_bypass with a string',
attr: 'proxy_cache_bypass',
value: '$pragma',
match: %r{^\s+proxy_cache_bypass\s+\$pragma;}
},
{
title: 'should set proxy_cache_bypass with an array',
attr: 'proxy_cache_bypass',
value: [
'$pragma',
'$cookie'
],
match: [
%r{^\s+proxy_cache_bypass\s+\$pragma;},
%r{^\s+proxy_cache_bypass\s+\$cookie;}
]
},
{
title: 'should set proxy_cache_lock with a string',
attr: 'proxy_cache_lock',
value: 'on',
match: %r{^\s+proxy_cache_lock\s+on;}
},
{
title: 'should set proxy_cache_lock with a string',
attr: 'proxy_cache_lock',
value: 'off',
match: %r{^\s+proxy_cache_lock\s+off;}
},
{
title: 'should set proxy_pass',
attr: 'proxy',
Expand Down
10 changes: 9 additions & 1 deletion templates/server/locations/proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<% if @proxy_cache -%>
proxy_cache <%= @proxy_cache %>;
<% end -%>
<% if @proxy_cache_valid && Array(@proxy_cache_valid).size > 0 -%>
<% if @proxy_cache_valid -%>
<%- Array(@proxy_cache_valid).each do |line| -%>
proxy_cache_valid <%= line %>;
<%- end -%>
Expand All @@ -46,4 +46,12 @@
<% if @proxy_cache_key -%>
proxy_cache_key <%= @proxy_cache_key %>;
<% end -%>
<% if @proxy_cache_bypass -%>
<%- Array(@proxy_cache_bypass).each do |line| -%>
proxy_cache_bypass <%= line %>;
<% end -%>
<% end -%>
<% if @proxy_cache_lock -%>
proxy_cache_lock <%= @proxy_cache_lock %>;
<% end -%>
<% end -%>

0 comments on commit 7783735

Please sign in to comment.