redirect 0.4.1 → 0.4.3
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/redirect/app.rb +14 -13
- data/lib/redirect/version.rb +1 -1
- data/spec/fixtures/public/sub/index.html +5 -0
- data/spec/rack_spec.rb +6 -0
- metadata +3 -1
data/lib/redirect/app.rb
CHANGED
@@ -5,10 +5,11 @@ module Redirect
|
|
5
5
|
class StaticFile
|
6
6
|
def initialize(path)
|
7
7
|
@path = path
|
8
|
+
@path = File.join(path, 'index.html') unless available?
|
8
9
|
end
|
9
10
|
|
10
11
|
def available?
|
11
|
-
expanded_path && expanded_path == path
|
12
|
+
expanded_path && expanded_path == path && File.file?(expanded_path)
|
12
13
|
end
|
13
14
|
|
14
15
|
def path
|
@@ -16,7 +17,7 @@ module Redirect
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def expanded_path
|
19
|
-
|
20
|
+
File.expand_path(path)
|
20
21
|
end
|
21
22
|
|
22
23
|
end
|
@@ -39,9 +40,9 @@ module Redirect
|
|
39
40
|
if request.fullpath == '/sitemap.xml'
|
40
41
|
return sitemap_response
|
41
42
|
end
|
42
|
-
if request.fullpath == '/' && index_file.available?
|
43
|
-
return index_response
|
44
|
-
end
|
43
|
+
# if request.fullpath == '/' && index_file.available?
|
44
|
+
# return index_response
|
45
|
+
# end
|
45
46
|
@redirects.each do |r|
|
46
47
|
if r.matches?(request.fullpath)
|
47
48
|
return redirects_response(r)
|
@@ -63,16 +64,16 @@ module Redirect
|
|
63
64
|
@request
|
64
65
|
end
|
65
66
|
|
66
|
-
def index_response
|
67
|
-
|
68
|
-
end
|
67
|
+
# def index_response
|
68
|
+
# send_file(index_file.expanded_path)
|
69
|
+
# end
|
69
70
|
|
70
|
-
def index_file
|
71
|
-
|
72
|
-
end
|
71
|
+
# def index_file
|
72
|
+
# @index_file = StaticFile.new(File.join(public_dir_path, 'index.html'))
|
73
|
+
# end
|
73
74
|
|
74
75
|
def public_dir_path
|
75
|
-
|
76
|
+
File.expand_path(public_dir)
|
76
77
|
end
|
77
78
|
|
78
79
|
def not_found_response
|
@@ -112,7 +113,7 @@ module Redirect
|
|
112
113
|
end
|
113
114
|
|
114
115
|
def static_file
|
115
|
-
|
116
|
+
StaticFile.new(public_dir_path + URI.unescape(request.path_info))
|
116
117
|
end
|
117
118
|
|
118
119
|
def static_response
|
data/lib/redirect/version.rb
CHANGED
data/spec/rack_spec.rb
CHANGED
@@ -68,6 +68,12 @@ describe "Redirect::App" do
|
|
68
68
|
headers.should include('Last-Modified')
|
69
69
|
end
|
70
70
|
|
71
|
+
it "serves GET request for dirs if it contains index.html" do
|
72
|
+
get "/sub"
|
73
|
+
status.should == 200
|
74
|
+
body.should == File.read('spec/fixtures/public/sub/index.html')
|
75
|
+
end
|
76
|
+
|
71
77
|
it "ignores GET request up the public directory" do
|
72
78
|
get "/../private"
|
73
79
|
status.should == 404
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: redirect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.4.
|
5
|
+
version: 0.4.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Petrik de Heus
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- redirect.gemspec
|
67
67
|
- spec/fixtures/private
|
68
68
|
- spec/fixtures/public/index.html
|
69
|
+
- spec/fixtures/public/sub/index.html
|
69
70
|
- spec/helper.rb
|
70
71
|
- spec/rack_spec.rb
|
71
72
|
has_rdoc: true
|
@@ -99,5 +100,6 @@ summary: Redirect is a simple Ruby redirect DSL build on Rack
|
|
99
100
|
test_files:
|
100
101
|
- spec/fixtures/private
|
101
102
|
- spec/fixtures/public/index.html
|
103
|
+
- spec/fixtures/public/sub/index.html
|
102
104
|
- spec/helper.rb
|
103
105
|
- spec/rack_spec.rb
|