rack_slashless 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack_slashless.rb +8 -8
- data/rack_slashless.gemspec +1 -1
- data/spec/rack_slashless_spec.rb +8 -7
- metadata +1 -1
data/lib/rack_slashless.rb
CHANGED
@@ -6,15 +6,15 @@ module Rack
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
-
|
10
|
-
|
11
|
-
|
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)
|
data/rack_slashless.gemspec
CHANGED
@@ -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.
|
11
|
+
gem.version = "0.0.5"
|
12
12
|
gem.license = "MIT"
|
13
13
|
|
14
14
|
gem.add_development_dependency 'rspec'
|
data/spec/rack_slashless_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Rack::Slashless do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "/" do
|
12
|
-
it "should
|
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
|
-
|
38
|
-
|
39
|
-
|
35
|
+
context "with a query_string" do
|
36
|
+
it "should redirect" do
|
37
|
+
get '/blog/?article=1', {}, {'SERVER_NAME' => 'example.org'}
|
40
38
|
|
41
|
-
|
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
|