serve-this 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/serve-this.rb +13 -10
- metadata +4 -4
data/lib/serve-this.rb
CHANGED
@@ -30,29 +30,32 @@ module ServeThis
|
|
30
30
|
else
|
31
31
|
|
32
32
|
# if we are looking at / lets try index.html
|
33
|
-
if path == "/" &&
|
33
|
+
if path == "/" && exists?("index.html")
|
34
34
|
env["PATH_INFO"] = "/index.html"
|
35
35
|
end
|
36
36
|
|
37
37
|
self.file_server.call(env)
|
38
38
|
end
|
39
39
|
end
|
40
|
+
|
41
|
+
def exists?(path)
|
42
|
+
File.exist?(File.join(self.root, path))
|
43
|
+
end
|
40
44
|
|
41
45
|
# prohibit showing system files
|
42
|
-
|
46
|
+
FORBIDDEN_REGEXP = /^(\.|config.ru$|Gemfile$|Gemfile.lock$)/i
|
43
47
|
|
44
48
|
def forbid?(path)
|
45
|
-
|
46
|
-
|
49
|
+
unescaped_path = ::Rack::Utils.unescape(path)
|
50
|
+
if unescaped_path.start_with?("/")
|
51
|
+
unescaped_path = unescaped_path[1..-1]
|
47
52
|
end
|
53
|
+
|
54
|
+
unescaped_path =~ FORBIDDEN_REGEXP
|
48
55
|
end
|
49
|
-
|
56
|
+
|
50
57
|
def forbid!
|
51
|
-
|
52
|
-
size = Rack::Utils.bytesize(body)
|
53
|
-
return [403, {"Content-Type" => "text/plain",
|
54
|
-
"Content-Length" => size.to_s,
|
55
|
-
"X-Cascade" => "pass"}, [body]]
|
58
|
+
self.file_server.forbidden
|
56
59
|
end
|
57
60
|
end
|
58
61
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serve-this
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthew Rudy Jacobs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-04-01 00:00:00 +08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|