From 708be8263d475044265dd1769e1e1e6876e5aa2b Mon Sep 17 00:00:00 2001 From: paschdan Date: Thu, 11 Dec 2014 17:43:33 +0100 Subject: [PATCH] moves rewrite_rules to location_header so it can be used by all location-types --- spec/defines/resource_location_spec.rb | 60 +++++++++---------------- templates/vhost/location_header.erb | 6 +++ templates/vhost/locations/directory.erb | 6 --- templates/vhost/locations/proxy.erb | 6 --- 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 1333033..d4fdab0 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -134,6 +134,26 @@ describe 'nginx::resource::location' do ], :match => /^\s+if \(a\) {\n\s++b;\n\s+\}/, }, + { + :title => 'should contain rewrite rules', + :attr => 'rewrite_rules', + :value => [ + '^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last', + '^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.ra last', + '^/users/(.*)$ /show?user=$1? last', + ], + :match => [ + /rewrite \^\(\/download\/\.\*\)\/media\/\(\.\*\)\\\.\.\*\$ \$1\/mp3\/\$2\.mp3 last/, + /rewrite \^\(\/download\/\.\*\)\/media\/\(\.\*\)\\\.\.\*\$ \$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 @@ -304,26 +324,6 @@ describe 'nginx::resource::location' do :value => ['name1','name2'], :match => ' index name1 name2;', }, - { - :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/ - }, { :title => 'should set auth_basic', :attr => 'auth_basic', @@ -596,26 +596,6 @@ describe 'nginx::resource::location' do :value => 'value', :match => %r'\s+proxy_set_body\s+value;', }, - { - :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 diff --git a/templates/vhost/location_header.erb b/templates/vhost/location_header.erb index dd8b046..d52f41a 100644 --- a/templates/vhost/location_header.erb +++ b/templates/vhost/location_header.erb @@ -54,3 +54,9 @@ <%= line %> <%- end -%> <% end -%> +<%- unless @rewrite_rules.nil? || @rewrite_rules.empty? -%> + + <%- @rewrite_rules.each do |rewrite_rule| -%> + rewrite <%= rewrite_rule %>; + <%- end -%> +<% end -%> diff --git a/templates/vhost/locations/directory.erb b/templates/vhost/locations/directory.erb index 5415a40..95c9737 100644 --- a/templates/vhost/locations/directory.erb +++ b/templates/vhost/locations/directory.erb @@ -11,12 +11,6 @@ <% if @try_files -%> try_files<% @try_files.each do |try| -%> <%= try %><% end -%>; <% end -%> -<%- unless @rewrite_rules.nil? || @rewrite_rules.empty? -%> - - <%- @rewrite_rules.each do |rewrite_rule| -%> - rewrite <%= rewrite_rule %>; - <%- end -%> -<% end -%> <% if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%> <%- if @auth_basic -%> diff --git a/templates/vhost/locations/proxy.erb b/templates/vhost/locations/proxy.erb index be9ae08..971a0ab 100644 --- a/templates/vhost/locations/proxy.erb +++ b/templates/vhost/locations/proxy.erb @@ -21,12 +21,6 @@ <% if @proxy_cache_valid -%> proxy_cache_valid <%= @proxy_cache_valid %>; <% end -%> -<%- unless @rewrite_rules.nil? || @rewrite_rules.empty? -%> - - <%- @rewrite_rules.each do |rewrite_rule| -%> - rewrite <%= rewrite_rule %>; - <%- end -%> -<% end -%> <% if instance_variables.any? { |iv| iv.to_s.include? 'auth_basic' } -%> <%- if @auth_basic -%>