Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Header directives in vhost context #575

Merged
merged 1 commit into from
Jan 24, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,20 @@ Specifies paths to additional static vhost-specific Apache configuration files.
This option is useful when you need to implement a unique and/or custom
configuration not supported by this module.

#####`headers`

Specifies additional response headers as per [the `mod_headers` documentation](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header).

```puppet
apache::vhost { 'site.name.fdqn':
headers => [
'add Strict-Transport-Security "max-age=15768000"',
'merge Cache-Control no-cache env=CGI',
],
}
```

#####`ip`

The IP address the vhost listens on. Defaults to 'undef'.
Expand Down
8 changes: 6 additions & 2 deletions manifests/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# of 'warn' is used.
# - The $access_log specifies if *_access.log directives should be configured.
# - The $ensure specifies if vhost file is present or absent.
# - The $headers is a list of Header statement strings as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
# - The $request_headers is a list of RequestHeader statement strings as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader
# - $aliases is a list of Alias hashes for mod_alias as per http://httpd.apache.org/docs/current/mod/mod_alias.html
# each statement is a hash in the form of { alias => '/alias', path => '/real/path/to/directory' }
Expand Down Expand Up @@ -149,6 +150,7 @@
$redirect_dest = undef,
$redirect_status = undef,
$rack_base_uris = undef,
$headers = undef,
$request_headers = undef,
$rewrites = undef,
$rewrite_rule = undef,
Expand Down Expand Up @@ -381,8 +383,8 @@
$priority_real = '25'
}

# Check if mod_headers is required to process $request_headers
if $request_headers {
# Check if mod_headers is required to process $headers/$request_headers
if $headers or $request_headers {
if ! defined(Class['apache::mod::headers']) {
include apache::mod::headers
}
Expand Down Expand Up @@ -449,6 +451,8 @@
# - $redirect_source
# - $redirect_dest
# - $redirect_status
# header fragment
# - $headers
# requestheader fragment:
# - $request_headers
# rewrite fragment:
Expand Down
9 changes: 9 additions & 0 deletions spec/defines/vhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@
/^ RackBaseURI \/rack2$/,
],
},
{
:title => 'should accept headers',
:attr => 'headers',
:value => ['add something', 'merge something_else'],
:match => [
/^ Header add something$/,
/^ Header merge something_else$/,
],
},
{
:title => 'should accept request headers',
:attr => 'request_headers',
Expand Down
1 change: 1 addition & 0 deletions templates/vhost.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<%= scope.function_template(['apache/vhost/_ssl.erb']) -%>
<%= scope.function_template(['apache/vhost/_suphp.erb']) -%>
<%= scope.function_template(['apache/vhost/_php_admin.erb']) -%>
<%= scope.function_template(['apache/vhost/_header.erb']) -%>
<%= scope.function_template(['apache/vhost/_requestheader.erb']) -%>
<%= scope.function_template(['apache/vhost/_wsgi.erb']) -%>
<%= scope.function_template(['apache/vhost/_custom_fragment.erb']) -%>
Expand Down
10 changes: 10 additions & 0 deletions templates/vhost/_header.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<% if @headers and ! @headers.empty? -%>

## Header rules
## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header
<%- Array(@headers).each do |header_statement| -%>
<%- if header_statement != '' -%>
Header <%= header_statement %>
<%- end -%>
<%- end -%>
<% end -%>