Merge pull request #618 from mmarod/passenger_header

Add passenger_set_header and passenger_env_var parameters for Passenger 5.0+
This commit is contained in:
Matthew Haughton 2015-04-29 23:30:37 -04:00
commit d1ff642c44
4 changed files with 74 additions and 0 deletions

View file

@ -127,6 +127,10 @@
# options like error level to the end.
# [*passenger_cgi_param*] - Allows one to define additional CGI environment
# variables to pass to the backend application
# [*passenger_set_header*] - Allows one to set headers to pass to the
# backend application (Passenger 5.0+)
# [*passenger_env_var*] - Allows one to set environemnt variables to pass
# to the backend application (Passenger 5.0+)
# [*log_by_lua*] - Run the Lua source code inlined as the
# <lua-script-str> at the log request processing phase.
# This does not replace the current access logs, but runs after.
@ -227,6 +231,8 @@ define nginx::resource::vhost (
$error_log = undef,
$format_log = 'combined',
$passenger_cgi_param = undef,
$passenger_set_header = undef,
$passenger_env_var = undef,
$log_by_lua = undef,
$log_by_lua_file = undef,
$use_default_location = true,
@ -408,6 +414,12 @@ define nginx::resource::vhost (
if ($passenger_cgi_param != undef) {
validate_hash($passenger_cgi_param)
}
if ($passenger_set_header != undef) {
validate_hash($passenger_set_header)
}
if ($passenger_env_var != undef) {
validate_hash($passenger_env_var)
}
if ($log_by_lua != undef) {
validate_string($log_by_lua)
}

View file

@ -853,6 +853,52 @@ describe 'nginx::resource::vhost' do
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_cgi_param test3 test value 3;/ ) }
end
context 'when passenger_set_header is set' do
let :params do default_params.merge({
:passenger_set_header => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }
}) end
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_header test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_header test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_set_header test3 test value 3;/ ) }
end
context 'when passenger_set_header is set and ssl => true' do
let :params do default_params.merge({
:passenger_set_header => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' },
:ssl => true,
:ssl_key => 'dummy.key',
:ssl_cert => 'dummy.cert',
}) end
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_header test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_header test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_set_header test3 test value 3;/ ) }
end
context 'when passenger_env_var is set' do
let :params do default_params.merge({
:passenger_env_var => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' }
}) end
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_env_var test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_env_var test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-header").with_content( /passenger_env_var test3 test value 3;/ ) }
end
context 'when passenger_env_var is set and ssl => true' do
let :params do default_params.merge({
:passenger_env_var => { 'test1' => 'test value 1', 'test2' => 'test value 2', 'test3' => 'test value 3' },
:ssl => true,
:ssl_key => 'dummy.key',
:ssl_cert => 'dummy.cert',
}) end
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_env_var test1 test value 1;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_env_var test2 test value 2;/ ) }
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content( /passenger_env_var test3 test value 3;/ ) }
end
context 'when vhost name is sanitized' do
let :title do 'www rspec-vhost com' end
let :params do default_params end

View file

@ -94,6 +94,16 @@ server {
passenger_set_cgi_param <%= key %> <%= @passenger_cgi_param[key] %>;
<%- end -%>
<% end -%>
<% if @passenger_set_header -%>
<%- @passenger_set_header.keys.sort.each do |key| -%>
passenger_set_header <%= key %> <%= @passenger_set_header[key] %>;
<%- end -%>
<% end -%>
<% if @passenger_env_var -%>
<%- @passenger_env_var.keys.sort.each do |key| -%>
passenger_env_var <%= key %> <%= @passenger_env_var[key] %>;
<%- end -%>
<% end -%>
<% if Array(@resolver).count > 0 -%>
resolver <% Array(@resolver).each do |r| %> <%= r %><% end %>;
<% end -%>

View file

@ -152,6 +152,12 @@ server {
<% Array(@passenger_cgi_param).each do |key,value| -%>
passenger_set_cgi_param <%= key %> <%= value %>;
<% end -%>
<% Array(@passenger_set_header).each do |key,value| -%>
passenger_set_header <%= key %> <%= value %>;
<% end -%>
<% Array(@passenger_env_var).each do |key,value| -%>
passenger_env_var <%= key %> <%= value %>;
<% end -%>
<% Array(@add_header).each do |key,value| -%>
add_header <%= key %> <%= value %>;
<% end -%>