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

Add add_header parameter to location #1160

Merged
merged 1 commit into from
Nov 22, 2017
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
2 changes: 2 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
# [*flv*] - Indicates whether or not this loation can be
# used for flv streaming. Default: false
# [*expires*] - Setup expires time for locations content
# [*add_header*] - Hash: Adds headers to the location block. If any are specified, locations will no longer inherit headers from the parent server context
#
#
# Actions:
Expand Down Expand Up @@ -216,6 +217,7 @@
Boolean $mp4 = false,
Boolean $flv = false,
Optional[String] $expires = undef,
Hash $add_header = {},
) {

if ! defined(Class['nginx']) {
Expand Down
37 changes: 37 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,43 @@
end
end

describe 'server_location_add_header template content' do
let :default_params do
{
location: 'location',
server: 'server1'
}
end

context 'location_add_header template with default params' do
let(:params) { default_params }

it { is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')) }
it 'doesn\'t add any add_header lines' do
is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')).
without_content(%r{add_header})
end
end

context 'location_add_header template with add_header parameter containing hash of two headers' do
let(:params) do
default_params.merge(
'add_header' => {
'X-Frame-Options' => 'SAMEORIGIN',
'X-Powered-By' => 'Puppet'
}
)
end

it 'contains both add_header lines' do
is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')).
with_content(%r{^\s+add_header\s+"X-Frame-Options"\s+"SAMEORIGIN";$})
is_expected.to contain_concat__fragment('server1-500-' + Digest::MD5.hexdigest('location')).
with_content(%r{^\s+add_header\s+"X-Powered-By"\s+"Puppet";$})
end
end
end

describe 'server_location_directory template content' do
let :default_params do
{
Expand Down
1 change: 1 addition & 0 deletions templates/server/location.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%= scope.function_template(['nginx/server/location_header.erb']) -%>
<%= scope.function_template(['nginx/server/locations/alias.erb']) -%>
<%= scope.function_template(['nginx/server/locations/headers.erb']) -%>
<%= scope.function_template(['nginx/server/locations/stub_status.erb']) -%>
<% if @fastcgi or @uwsgi or @proxy -%>
<%= scope.function_template(['nginx/server/locations/proxy.erb']) -%>
Expand Down
3 changes: 3 additions & 0 deletions templates/server/locations/headers.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%- @add_header.keys.sort.each do |key| -%>
add_header "<%= key %>" "<%= @add_header[key] %>";
<%- end -%>