Skip to content

Commit 0168a74

Browse files
authored
Merge pull request #2365 from bastelfreak/proxyaddheaders
vhost: Make ProxyAddHeaders configureable
2 parents 73adc51 + 3f6e5ee commit 0168a74

File tree

3 files changed

+119
-10
lines changed

3 files changed

+119
-10
lines changed

manifests/vhost.pp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,14 +2137,16 @@
21372137
if $directories {
21382138
$_directories = $directories
21392139
} elsif $docroot {
2140-
$_directories = [{
2141-
provider => 'directory',
2142-
path => $docroot,
2143-
options => $options,
2144-
allow_override => $override,
2145-
directoryindex => $directoryindex,
2146-
require => 'all granted',
2147-
}]
2140+
$_directories = [
2141+
{
2142+
provider => 'directory',
2143+
path => $docroot,
2144+
options => $options,
2145+
allow_override => $override,
2146+
directoryindex => $directoryindex,
2147+
require => 'all granted',
2148+
}
2149+
]
21482150
} else {
21492151
$_directories = undef
21502152
}
@@ -2448,7 +2450,7 @@
24482450
# - $proxy_preserve_host
24492451
# - $proxy_add_headers
24502452
# - $no_proxy_uris
2451-
if ($proxy_dest or $proxy_pass or $proxy_pass_match or $proxy_dest_match or $proxy_preserve_host) and $ensure == 'present' {
2453+
if ($proxy_dest or $proxy_pass or $proxy_pass_match or $proxy_dest_match or $proxy_preserve_host or ($proxy_add_headers =~ NotUndef)) and $ensure == 'present' {
24522454
include apache::mod::proxy_http
24532455

24542456
concat::fragment { "${name}-proxy":

spec/defines/vhost_spec.rb

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,113 @@
902902
)
903903
}
904904
end
905+
context 'vhost with proxy_add_headers true' do
906+
let :params do
907+
{
908+
'docroot' => '/var/www/foo',
909+
'manage_docroot' => false,
910+
'virtual_docroot' => true,
911+
'virtual_use_default_docroot' => false,
912+
'port' => 8080,
913+
'ip' => '127.0.0.1',
914+
'ip_based' => true,
915+
'add_listen' => false,
916+
'serveradmin' => 'foo@localhost',
917+
'priority' => 30,
918+
'default_vhost' => true,
919+
'servername' => 'example.com',
920+
'serveraliases' => ['test-example.com'],
921+
'options' => ['MultiView'],
922+
'override' => ['All'],
923+
'directoryindex' => 'index.html',
924+
'vhost_name' => 'test',
925+
'proxy_add_headers' => true,
926+
}
927+
end
928+
929+
it { is_expected.to compile }
930+
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders On}) }
931+
end
932+
context 'vhost with proxy_add_headers false' do
933+
let :params do
934+
{
935+
'docroot' => '/var/www/foo',
936+
'manage_docroot' => false,
937+
'virtual_docroot' => true,
938+
'virtual_use_default_docroot' => false,
939+
'port' => 8080,
940+
'ip' => '127.0.0.1',
941+
'ip_based' => true,
942+
'add_listen' => false,
943+
'serveradmin' => 'foo@localhost',
944+
'priority' => 30,
945+
'default_vhost' => true,
946+
'servername' => 'example.com',
947+
'serveraliases' => ['test-example.com'],
948+
'options' => ['MultiView'],
949+
'override' => ['All'],
950+
'directoryindex' => 'index.html',
951+
'vhost_name' => 'test',
952+
'proxy_add_headers' => false,
953+
}
954+
end
955+
956+
it { is_expected.to compile }
957+
it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders Off}) }
958+
end
959+
context 'vhost without proxy' do
960+
let :params do
961+
{
962+
'docroot' => '/var/www/foo',
963+
'manage_docroot' => false,
964+
'virtual_docroot' => true,
965+
'virtual_use_default_docroot' => false,
966+
'port' => 8080,
967+
'ip' => '127.0.0.1',
968+
'ip_based' => true,
969+
'add_listen' => false,
970+
'serveradmin' => 'foo@localhost',
971+
'priority' => 30,
972+
'default_vhost' => true,
973+
'servername' => 'example.com',
974+
'serveraliases' => ['test-example.com'],
975+
'options' => ['MultiView'],
976+
'override' => ['All'],
977+
'directoryindex' => 'index.html',
978+
'vhost_name' => 'test',
979+
}
980+
end
981+
982+
it { is_expected.to compile }
983+
it { is_expected.not_to contain_concat__fragment('rspec.example.com-proxy') }
984+
end
985+
context 'vhost without proxy_add_headers' do
986+
let :params do
987+
{
988+
'docroot' => '/var/www/foo',
989+
'manage_docroot' => false,
990+
'virtual_docroot' => true,
991+
'virtual_use_default_docroot' => false,
992+
'port' => 8080,
993+
'ip' => '127.0.0.1',
994+
'ip_based' => true,
995+
'add_listen' => false,
996+
'serveradmin' => 'foo@localhost',
997+
'priority' => 30,
998+
'default_vhost' => true,
999+
'servername' => 'example.com',
1000+
'serveraliases' => ['test-example.com'],
1001+
'options' => ['MultiView'],
1002+
'override' => ['All'],
1003+
'directoryindex' => 'index.html',
1004+
'vhost_name' => 'test',
1005+
'proxy_preserve_host' => true,
1006+
}
1007+
end
1008+
1009+
it { is_expected.to compile }
1010+
it { is_expected.not_to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders}) }
1011+
end
9051012
context 'vhost with scheme and port in servername and use_servername_for_filenames' do
9061013
let :params do
9071014
{

templates/vhost/_proxy.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<% if @proxy_dest or @proxy_pass or @proxy_pass_match or @proxy_dest_match -%>
1+
<% if @proxy_dest or @proxy_pass or @proxy_pass_match or @proxy_dest_match or defined?(@proxy_add_headers) -%>
22

33
## Proxy rules
44
ProxyRequests <%= scope.call_function('apache::bool2httpd', @proxy_requests) %>

0 commit comments

Comments
 (0)