From c767fbbb72066f414ff231fff993695306b73100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20K=C3=B6rner?= Date: Thu, 14 Aug 2014 12:54:35 +0200 Subject: [PATCH] Added add_header to location --- manifests/resource/location.pp | 6 ++++++ spec/defines/resource_location_spec.rb | 6 ++++++ spec/defines/resource_vhost_spec.rb | 6 ++++++ templates/vhost/location_header.erb | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index 2d4ddc642..43ad815ac 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -15,6 +15,8 @@ # [*location_deny*] - Array: Locations to deny connections from. # [*www_root*] - Specifies the location on disk for files to be # read from. Cannot be set in conjunction with $proxy +# [*add_header*] - Hash: Adds headers to the HTTP response when +# response code is equal to 200, 204, 301, 302 or 304. # [*autoindex*] - Set it on 'on' to activate autoindex directory # listing. Undef by default. # [*index_files*] - Default index files for NGINX to read when @@ -126,6 +128,7 @@ $location = $name, $vhost = undef, $www_root = undef, + $add_header = undef, $autoindex = undef, $index_files = [ 'index.html', @@ -185,6 +188,9 @@ if ($www_root != undef) { validate_string($www_root) } + if ($add_header != undef) { + validate_hash($add_header) + } if ($autoindex != undef) { validate_string($autoindex) } diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 776e7d1bb..17f2adc6f 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -72,6 +72,12 @@ ' deny 10.0.0.1;', ], }, + { + :title => 'should set add_header option', + :attr => 'add_header', + :value => {'CUSTOM_PARAM' => 'value'}, + :match => /add_header\s+CUSTOM_PARAM\s+value;/, + }, { :title => 'should contain ordered prepended directives', :attr => 'location_cfg_prepend', diff --git a/spec/defines/resource_vhost_spec.rb b/spec/defines/resource_vhost_spec.rb index 81568e905..901cb7ae3 100644 --- a/spec/defines/resource_vhost_spec.rb +++ b/spec/defines/resource_vhost_spec.rb @@ -408,6 +408,12 @@ :value => 'spdy default', :match => ' listen [::]:443 ssl spdy default;', }, + { + :title => 'should set add_header option', + :attr => 'add_header', + :value => {'CUSTOM_PARAM' => 'value'}, + :match => /add_header\s+CUSTOM_PARAM\s+value;/, + }, { :title => 'should set servername(s)', :attr => 'server_name', diff --git a/templates/vhost/location_header.erb b/templates/vhost/location_header.erb index e6c4cddf2..0f827b6c2 100644 --- a/templates/vhost/location_header.erb +++ b/templates/vhost/location_header.erb @@ -12,6 +12,11 @@ deny <%= deny_rule %>; <%- end -%> <% end -%> +<% if @add_header -%> + <%- @add_header.each do |key,value| -%> + add_header <%= key %> <%= value %>; + <%- end -%> +<% end -%> <% if @location_custom_cfg_prepend -%> <%- @location_custom_cfg_prepend.each do |key,value| -%> <%- if value.is_a?(Hash) -%>