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

added rewrite to location/proxy & vhost #235

Merged
merged 2 commits into from
Jan 13, 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
2 changes: 2 additions & 0 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
$proxy_set_body = undef,
$auth_basic = undef,
$auth_basic_user_file = undef,
$rewrite_rules = [],
$priority = 500
) {
File {
Expand Down Expand Up @@ -207,6 +208,7 @@
if !is_integer($priority) {
fail('$priority must be an integer.')
}
validate_array($rewrite_rules)
if ($priority < 401) or ($priority > 599) {
fail('$priority must be in the range 401-599.')
}
Expand Down
3 changes: 3 additions & 0 deletions manifests/resource/vhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
$error_log = undef,
$passenger_cgi_param = undef,
$use_default_location = true,
$rewrite_rules = [],
) {

validate_re($ensure, '^(present|absent)$',
Expand Down Expand Up @@ -298,6 +299,7 @@
validate_hash($passenger_cgi_param)
}
validate_bool($use_default_location)
validate_array($rewrite_rules)

# Variables
$vhost_dir = "${nginx::config::nx_conf_dir}/sites-available"
Expand Down Expand Up @@ -381,6 +383,7 @@
index_files => [],
location_custom_cfg => $location_custom_cfg,
notify => Class['nginx::service'],
rewrite_rules => $rewrite_rules,
}
} else {
$root = $www_root
Expand Down
40 changes: 40 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,26 @@
' test2 test value 2;',
],
},
{
:title => 'should contain rewrite rules',
:attr => 'rewrite_rules',
:value => [
'^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last',
'^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last',
'^/users/(.*)$ /show?user=$1? last',
],
:match => [
' rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;',
' rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;',
' rewrite ^/users/(.*)$ /show?user=$1? last;',
],
},
{
:title => 'should not set rewrite_rules',
:attr => 'rewrite_rules',
:value => [],
:notmatch => /rewrite/
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :default_params do { :location => 'location', :proxy => 'proxy_value', :vhost => 'vhost1' } end
Expand Down Expand Up @@ -373,6 +393,26 @@
' test2 test value 2;',
],
},
{
:title => 'should contain rewrite rules',
:attr => 'rewrite_rules',
:value => [
'^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last',
'^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last',
'^/users/(.*)$ /show?user=$1? last',
],
:match => [
' rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;',
' rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra last;',
' rewrite ^/users/(.*)$ /show?user=$1? last;',
],
},
{
:title => 'should not set rewrite_rules',
:attr => 'rewrite_rules',
:value => [],
:notmatch => /rewrite/
},
].each do |param|
context "when #{param[:attr]} is #{param[:value]}" do
let :default_params do { :location => 'location', :www_root => '/var/www/root', :vhost => 'vhost1' } end
Expand Down
4 changes: 3 additions & 1 deletion templates/vhost/vhost_location_directory.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<% if @index_files.count > 0 -%>
index <% Array(@index_files).each do |i| %> <%= i %><% end %>;
<% end -%>
<% @rewrite_rules.each do |rewrite_rule| -%>
rewrite <%= rewrite_rule %>;
<% end -%>
<% if defined? @auth_basic -%>
auth_basic "<%= @auth_basic %>";
<% end -%>
Expand All @@ -30,4 +33,3 @@
<%= key %> <%= value %>;
<% end -%><% end -%>
}

3 changes: 3 additions & 0 deletions templates/vhost/vhost_location_proxy.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<% if @proxy_set_body -%>
proxy_set_body <%= @proxy_set_body %>;
<% end -%>
<% @rewrite_rules.each do |rewrite_rule| -%>
rewrite <%= rewrite_rule %>;
<% end -%>
<% if @location_cfg_append -%><% @location_cfg_append.sort_by {|k,v| k}.each do |key,value| -%>
<%= key %> <%= value %>;
<% end -%><% end -%>
Expand Down