Skip to content

Commit f28a715

Browse files
committed
Merge pull request #1064 from stevenpost/feature/default_type
Apache: allow setting the default type
2 parents 641357d + 97e9352 commit f28a715

4 files changed

Lines changed: 74 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ Sets up a default SSL virtual host. Defaults to 'false'. If set to 'true', sets
313313

314314
SSL vhosts only respond to HTTPS queries.
315315

316+
#####`default_type`
317+
318+
(Apache httpd 2.2 only) MIME content-type that will be sent if the server cannot determine a type in any other way. This directive has been deprecated in Apache httpd 2.4, and only exists there for backwards compatibility of configuration files.
319+
316320
#####`default_vhost`
317321

318322
Sets up a default virtual host. Defaults to 'true', set to 'false' to set up [customized virtual hosts](#configure-a-virtual-host).

manifests/init.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
$default_ssl_crl_path = undef,
2828
$default_ssl_crl = undef,
2929
$default_ssl_crl_check = undef,
30+
$default_type = 'none',
3031
$ip = undef,
3132
$service_enable = true,
3233
$service_manage = true,

spec/classes/apache_spec.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,40 @@
149149
) }
150150
end
151151

152+
describe "Check default type" do
153+
context "with Apache version < 2.4" do
154+
let :params do
155+
{
156+
:apache_version => '2.2',
157+
}
158+
end
159+
160+
context "when default_type => 'none'" do
161+
let :params do
162+
{ :default_type => 'none' }
163+
end
164+
165+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType none$} }
166+
end
167+
context "when default_type => 'text/plain'" do
168+
let :params do
169+
{ :default_type => 'text/plain' }
170+
end
171+
172+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^DefaultType text/plain$} }
173+
end
174+
end
175+
176+
context "with Apache version >= 2.4" do
177+
let :params do
178+
{
179+
:apache_version => '2.4',
180+
}
181+
end
182+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^DefaultType [.]*$} }
183+
end
184+
end
185+
152186
describe "Don't create user resource" do
153187
context "when parameter manage_user is false" do
154188
let :params do
@@ -353,6 +387,38 @@
353387
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^AddDefaultCharset none$} }
354388
end
355389

390+
context "with Apache version < 2.4" do
391+
let :params do
392+
{
393+
:apache_version => '2.2',
394+
}
395+
end
396+
397+
context "when default_type => 'none'" do
398+
let :params do
399+
{ :default_type => 'none' }
400+
end
401+
402+
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType none$} }
403+
end
404+
context "when default_type => 'text/plain'" do
405+
let :params do
406+
{ :default_type => 'text/plain' }
407+
end
408+
409+
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^DefaultType text/plain$} }
410+
end
411+
end
412+
413+
context "with Apache version >= 2.4" do
414+
let :params do
415+
{
416+
:apache_version => '2.4',
417+
}
418+
end
419+
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").without_content %r{^DefaultType [.]*$} }
420+
end
421+
356422
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/site\.d/\*"$} }
357423
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} }
358424
it { is_expected.to contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} }

templates/httpd.conf.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ AccessFileName .htaccess
3434
AddDefaultCharset <%= @default_charset %>
3535
<% end -%>
3636

37-
DefaultType none
37+
<%- if scope.function_versioncmp([@apache_version, '2.4']) < 0 -%>
38+
DefaultType <%= @default_type %>
39+
<%- end -%>
3840
HostnameLookups Off
3941
ErrorLog "<%= @logroot %>/<%= @error_log %>"
4042
LogLevel <%= @log_level %>

0 commit comments

Comments
 (0)