rack_slashless 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack_slashless (0.0.6)
4
+ rack_slashless (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -7,13 +7,8 @@ module Rack
7
7
 
8
8
  def call(env)
9
9
  request = Rack::Request.new(env)
10
- if request.get? && request.path_info.match(/\w+\/$/)
11
- destination = [
12
- "#{request.scheme}://",
13
- request.env['SERVER_NAME'],
14
- request.path_info[0..-2],
15
- (request.query_string.empty? ? '' : "?#{request.query_string}")
16
- ].join
10
+ if request.get? && request.path_info.match(/.+\/$/)
11
+ destination = request.url.gsub(/\/(\?.*)?$/,'\1')
17
12
  [301, {'Location' => destination}, ["Redirecting to #{destination}"]]
18
13
  else
19
14
  @app.call(env)
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.test_files = `git ls-files -- spec/*`.split("\n")
9
9
  gem.name = "rack_slashless"
10
10
  gem.require_paths = ["lib"]
11
- gem.version = "0.0.6"
11
+ gem.version = "0.0.7"
12
12
  gem.license = "MIT"
13
13
 
14
14
  gem.add_development_dependency 'rspec', '>= 2'
@@ -8,45 +8,59 @@ describe Rack::Slashless do
8
8
  end
9
9
  end
10
10
 
11
- describe "/" do
12
- it "should not redirect" do
13
- get '/', {}, {'SERVER_NAME' => 'www.example.org'}
14
-
15
- last_response.status.should == 200
11
+ context 'GET requests' do
12
+
13
+ context 'without a path' do
14
+ it 'should not redirect' do
15
+ get '/', {}, 'HTTP_HOST' => 'example.org'
16
+ last_response.status.should == 200
17
+ end
16
18
  end
17
19
 
18
- context "without a subdomain" do
19
- it "should redirect to server name" do
20
- get '/', {}, {'SERVER_NAME' => 'example.org'}
21
-
20
+ context 'with a path that does not include a trailing slash' do
21
+ it 'should not redirect' do
22
+ get '/blog', {}, 'HTTP_HOST' => 'example.org'
22
23
  last_response.status.should == 200
23
24
  end
24
25
  end
25
- end
26
26
 
27
- describe "/blog/" do
28
- it "should redirect to /blog" do
29
- get '/blog/', {}, {'SERVER_NAME' => 'www.example.org'}
27
+ context 'with a path that includes a trailing slash' do
28
+ it 'should redirect to a url without a trailing slash' do
29
+ get '/blog/', {}, 'HTTP_HOST' => 'example.org'
30
+ last_response.status.should == 301
31
+ last_response['Location'].should eql('http://example.org/blog')
32
+ end
33
+ end
30
34
 
31
- last_response.status.should == 301
32
- last_response['Location'].should eql('http://www.example.org/blog')
35
+ context 'with a query string' do
36
+ it 'should retain the query string when redirecting' do
37
+ get '/blog/?article=1', {}, 'HTTP_HOST' => 'example.org'
38
+ last_response.status.should == 301
39
+ last_response['Location'].should eql('http://example.org/blog?article=1')
40
+ end
33
41
  end
34
42
 
35
- context "with a query_string" do
36
- it "should redirect" do
37
- get '/blog/?article=1', {}, {'SERVER_NAME' => 'example.org'}
43
+ context 'with a port' do
44
+ it 'should retain the port when redirecting' do
45
+ get '/blog/', {}, 'HTTP_HOST' => 'example.org', 'SERVER_PORT' => '3000'
46
+ last_response.status.should == 301
47
+ last_response['Location'].should eql('http://example.org:3000/blog')
48
+ end
49
+ end
38
50
 
51
+ context 'with a subdomain' do
52
+ it 'should retain the subdomain when redirecting' do
53
+ get '/blog/', {}, 'HTTP_HOST' => 'www.example.org'
39
54
  last_response.status.should == 301
40
- last_response['Location'].should eql('http://example.org/blog?article=1')
55
+ last_response['Location'].should eql('http://www.example.org/blog')
41
56
  end
42
57
  end
43
58
 
44
59
  end
45
60
 
46
- describe "POST /blog" do
47
- it "should not redirect" do
48
- post '/blog/', {}, {'SERVER_NAME' => 'www.example.org'}
49
-
61
+ context 'POST requests' do
62
+ it 'should not redirect' do
63
+ post '/blog/', {}, 'HTTP_HOST' => 'example.org'
50
64
  last_response.status.should == 200
51
65
  end
52
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_slashless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-15 00:00:00.000000000 Z
12
+ date: 2012-12-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec