Skip to content

Commit

Permalink
Merge pull request #914 from tfhartmann/tfhartmann_proxy_pass
Browse files Browse the repository at this point in the history
Support parameters along with proxy_pass now w/ tests
  • Loading branch information
Morgan Haskel committed Nov 5, 2014
2 parents 5bba3c9 + 0edb041 commit fba4862
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ Specifies the destination address of a [ProxyPass](http://httpd.apache.org/docs/

#####`proxy_pass`

Specifies an array of `path => URI` for a [ProxyPass](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) configuration. Defaults to 'undef'.
Specifies an array of `path => URI` for a [ProxyPass](http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxypass) configuration. Defaults to 'undef'. Optionally parameters can be added as an array.

```puppet
apache::vhost { 'site.name.fdqn':
Expand All @@ -1149,6 +1149,10 @@ apache::vhost { 'site.name.fdqn':
{ 'path' => '/c', 'url' => 'http://backend-a/c', 'params' => 'max=20 ttl=120 retry=300' },
{ 'path' => '/l', 'url' => 'http://backend-xy',
'reverse_urls' => ['http://backend-x', 'http://backend-y'] },
{ 'path' => '/d', 'url' => 'http://backend-a/d',
'params' => { 'retry' => '0', 'timeout' => '5' }, },
{ 'path' => '/e', 'url' => 'http://backend-a/e',
'keywords' => ['nocanon', 'interpolate'] },
],
}
```
Expand Down
16 changes: 13 additions & 3 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@
'proxy_dest' => '/',
'proxy_pass' => [
{
'path' => '/a',
'url' => 'http://backend-a/'
'path' => '/a',
'url' => 'http://backend-a/',
'keywords' => ['noquery', 'interpolate'],
'params' => {
'retry' => '0',
'timeout' => '5'
}
}
],
'suphp_addhandler' => 'foo',
Expand Down Expand Up @@ -296,7 +301,12 @@
it { is_expected.to contain_concat__fragment('rspec.example.com-action') }
it { is_expected.to contain_concat__fragment('rspec.example.com-block') }
it { is_expected.to contain_concat__fragment('rspec.example.com-error_document') }
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy') }
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(
/retry=0/) }
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(
/timeout=5/) }
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(
/noquery interpolate/) }
it { is_expected.to contain_concat__fragment('rspec.example.com-rack') }
it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') }
it { is_expected.to contain_concat__fragment('rspec.example.com-rewrite') }
Expand Down
9 changes: 7 additions & 2 deletions templates/vhost/_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@
ProxyPreserveHost On
<%- end -%>
<%- [@proxy_pass].flatten.compact.each do |proxy| -%>
ProxyPass <%= proxy['path'] %> <%= proxy['url'] %> <%- if !proxy['params'].nil? -%> <%= proxy['params'] %> <%- end -%>

ProxyPass <%= proxy['path'] %> <%= proxy['url'] -%>
<%- if proxy['params'] -%>
<%- proxy['params'].each_pair do |key, value| -%> <%= key %>=<%= value -%>
<%- end -%>
<%- end -%>
<%- if proxy['keywords'] %> <%= proxy['keywords'].join(' ') -%>
<%- end %>
<Location <%= proxy['path']%>>
<%- if proxy['reverse_urls'].nil? -%>
ProxyPassReverse <%= proxy['url'] %>
Expand Down
66 changes: 66 additions & 0 deletions tests/vhost_proxypass.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## vhost with proxyPass directive
# NB: Please see the other vhost_*.pp example files for further
# examples.

# Base class. Declares default vhost on port 80 and default ssl
# vhost on port 443 listening on all interfaces and serving
# $apache::docroot
class { 'apache': }

# Most basic vhost with proxy_pass
apache::vhost { 'first.example.com':
port => 80,
docroot => '/var/www/first',
proxy_pass => [
{
'path' => '/first',
'url' => 'http://localhost:8080/first'
},
],
}

# vhost with proxy_pass and parameters
apache::vhost { 'second.example.com':
port => 80,
docroot => '/var/www/second',
proxy_pass => [
{
'path' => '/second',
'url' => 'http://localhost:8080/second',
'params' => {
'retry' => '0',
'timeout' => '5'
}
},
],
}

# vhost with proxy_pass and keywords
apache::vhost { 'third.example.com':
port => 80,
docroot => '/var/www/third',
proxy_pass => [
{
'path' => '/third',
'url' => 'http://localhost:8080/third',
'keywords' => ['noquery', 'interpolate']
},
],
}

# vhost with proxy_pass, parameters and keywords
apache::vhost { 'fourth.example.com':
port => 80,
docroot => '/var/www/fourth',
proxy_pass => [
{
'path' => '/fourth',
'url' => 'http://localhost:8080/fourth',
'params' => {
'retry' => '0',
'timeout' => '5'
},
'keywords' => ['noquery', 'interpolate']
},
],
}

0 comments on commit fba4862

Please sign in to comment.