rack_slashless 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,15 +6,15 @@ module Rack
6
6
  end
7
7
 
8
8
  def call(env)
9
- if env['REQUEST_METHOD'] == "GET" && env['QUERY_STRING'].empty? && env['PATH_INFO'].match(/\w+\/$/)
10
- parts = env['SERVER_NAME'].split('.')
11
- suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
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
12
17
 
13
- destination = "#{env['rack.url_scheme']}://"
14
- destination << "#{prefix}." if prefix
15
- destination << "#{chunk}.#{suffix}"
16
- destination << "#{env['PATH_INFO']}"[0..-2]
17
-
18
18
  [301, {'Location' => destination}, ['Redirecting to the same url but with the ending /']]
19
19
  else
20
20
  @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.4"
11
+ gem.version = "0.0.5"
12
12
  gem.license = "MIT"
13
13
 
14
14
  gem.add_development_dependency 'rspec'
@@ -9,7 +9,7 @@ describe Rack::Slashless do
9
9
  end
10
10
 
11
11
  describe "/" do
12
- it "should success to server name" do
12
+ it "should not redirect" do
13
13
  get '/', {}, {'SERVER_NAME' => 'www.example.org'}
14
14
 
15
15
  last_response.status.should == 200
@@ -22,7 +22,6 @@ describe Rack::Slashless do
22
22
  last_response.status.should == 200
23
23
  end
24
24
  end
25
-
26
25
  end
27
26
 
28
27
  describe "/blog/" do
@@ -32,14 +31,16 @@ describe Rack::Slashless do
32
31
  last_response.status.should == 301
33
32
  last_response['Location'].should eql('http://www.example.org/blog')
34
33
  end
35
- end
36
34
 
37
- describe "/blog?article=1" do
38
- it "should not redirect" do
39
- get '/blog?article=1', {}, {'SERVER_NAME' => 'www.example.org'}
35
+ context "with a query_string" do
36
+ it "should redirect" do
37
+ get '/blog/?article=1', {}, {'SERVER_NAME' => 'example.org'}
40
38
 
41
- last_response.status.should == 200
39
+ last_response.status.should == 301
40
+ last_response['Location'].should eql('http://example.org/blog?article=1')
41
+ end
42
42
  end
43
+
43
44
  end
44
45
 
45
46
  describe "POST /blog" do
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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: