From fcf11a8b187585703a0661986a3a58a05d33ef55 Mon Sep 17 00:00:00 2001 From: Harry Danes Date: Tue, 24 Dec 2013 13:07:58 +0100 Subject: [PATCH 1/2] Add the possibility to add a header to the HTTP response when response code is equal to 200, 204, 301, 302 or 304. --- manifests/resource/vhost.pp | 3 +++ templates/vhost/vhost_header.erb | 3 +++ templates/vhost/vhost_ssl_header.erb | 3 +++ 3 files changed, 9 insertions(+) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 8117e05e4..2c21b4c3f 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -23,6 +23,8 @@ # [*ipv6_listen_options*] - Extra options for listen directive like 'default' # to catchall. Template will allways add ipv6only=on. While issue # jfryman/puppet-nginx#30 is discussed, default value is 'default'. +# [*add_header*] - Adds headers to the HTTP response when +# response code is equal to 200, 204, 301, 302 or 304. # [*index_files*] - Default index files for NGINX to read when # traversing a directory # [*autoindex*] - Set it on 'on' to activate autoindex directory @@ -104,6 +106,7 @@ $ipv6_listen_ip = '::', $ipv6_listen_port = '80', $ipv6_listen_options = 'default', + $add_header = undef, $ssl = false, $ssl_cert = undef, $ssl_key = undef, diff --git a/templates/vhost/vhost_header.erb b/templates/vhost/vhost_header.erb index 231160d52..d552fef7b 100644 --- a/templates/vhost/vhost_header.erb +++ b/templates/vhost/vhost_header.erb @@ -26,6 +26,9 @@ server { <% @proxy_set_header.each do |header| -%> proxy_set_header <%= header %>; <% end -%> +<% if @add_header -%><% @add_header.each do |key,value| -%> + add_header <%= key %> <%= value %>; +<% end -%><% end -%> <% if @rewrite_to_https -%> if ($ssl_protocol = "") { return 301 https://$host$request_uri; diff --git a/templates/vhost/vhost_ssl_header.erb b/templates/vhost/vhost_ssl_header.erb index 949da5653..99f0e1da1 100644 --- a/templates/vhost/vhost_ssl_header.erb +++ b/templates/vhost/vhost_ssl_header.erb @@ -33,5 +33,8 @@ server { <% @proxy_set_header.each do |header| -%> proxy_set_header <%= header %>; <% end -%> +<% if @add_header -%><% @add_header.each do |key,value| -%> + add_header <%= key %> <%= value %>; +<% end -%><% end -%> From e0b8cb5f3fc53ddb2f5b6c95ceeecd9ff3e15267 Mon Sep 17 00:00:00 2001 From: Harry Danes Date: Tue, 24 Dec 2013 19:47:15 +0100 Subject: [PATCH 2/2] Implemented input validation - type hash - for the (optional) add_header parameter. --- manifests/resource/vhost.pp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifests/resource/vhost.pp b/manifests/resource/vhost.pp index 2c21b4c3f..6af847434 100644 --- a/manifests/resource/vhost.pp +++ b/manifests/resource/vhost.pp @@ -23,7 +23,7 @@ # [*ipv6_listen_options*] - Extra options for listen directive like 'default' # to catchall. Template will allways add ipv6only=on. While issue # jfryman/puppet-nginx#30 is discussed, default value is 'default'. -# [*add_header*] - Adds headers to the HTTP response when +# [*add_header*] - Hash: Adds headers to the HTTP response when # response code is equal to 200, 204, 301, 302 or 304. # [*index_files*] - Default index files for NGINX to read when # traversing a directory @@ -154,6 +154,9 @@ validate_array($proxy_set_header) validate_array($index_files) validate_array($server_name) + if ($add_header != undef) { + validate_hash($add_header) + } # Variables $vhost_dir = "${nginx::config::nx_conf_dir}/sites-available"