tansu 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/tansu/static.rb +50 -0
- data/lib/tansu/version.rb +1 -1
- data/lib/tansu.rb +13 -11
- data/tansu.gemspec +2 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3255da4f480f3428f7a2c65590f171229879256d
|
4
|
+
data.tar.gz: 53d76f95e8831b43946cafb6ad64a32224757e07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09c18f040d39a93ba9e7ae35c5bbc14c6a5ea41464616e19b199528598e800a4da35fa2762e691a4211335f4884153800e2b352916de3c19b40325dbedfbd643
|
7
|
+
data.tar.gz: 14b626ceb849b3f8600e5f58fee281d08f52668bd86e84e6c9f21cc01794922c663f97adb22ef3b666e4162d64d4ff78fff2949fb6e0bf281a41f6e69592330c
|
data/README.md
CHANGED
data/lib/tansu/static.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Tansu
|
2
|
+
class Static
|
3
|
+
ACCEPT_METHODS = %w(GET HEAD)
|
4
|
+
|
5
|
+
def initialize(app, root)
|
6
|
+
@app = app
|
7
|
+
@root = root
|
8
|
+
@file_server = Rack::File.new(root)
|
9
|
+
@parser = URI::Parser.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def match(path)
|
13
|
+
return false unless path = verify(path)
|
14
|
+
|
15
|
+
path = Rack::Utils.clean_path_info(path)
|
16
|
+
|
17
|
+
match?(path) && path
|
18
|
+
end
|
19
|
+
|
20
|
+
def call(env)
|
21
|
+
method = env['REQUEST_METHOD']
|
22
|
+
path = env['PATH_INFO']
|
23
|
+
|
24
|
+
if ACCEPT_METHODS.include?(method) && path = match(path)
|
25
|
+
env['PATH_INFO'] = path
|
26
|
+
|
27
|
+
@file_server.(env)
|
28
|
+
else
|
29
|
+
@app.(env)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def verify(path)
|
36
|
+
encode = Encoding::UTF_8 if (encode = path.encoding) == Encoding::US_ASCII
|
37
|
+
path = @parser.unescape(path).force_encoding(encode)
|
38
|
+
|
39
|
+
path.valid_encoding? ? path : false
|
40
|
+
end
|
41
|
+
|
42
|
+
def match?(path)
|
43
|
+
path = File.join(@root, path)
|
44
|
+
|
45
|
+
File.file?(path) && File.readable?(path)
|
46
|
+
rescue SystemCallError
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/tansu/version.rb
CHANGED
data/lib/tansu.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'uri'
|
2
|
+
require 'rack'
|
3
|
+
require 'minicontext'
|
4
|
+
require 'tilt'
|
5
|
+
require 'rack/protection'
|
5
6
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
7
|
+
require 'tansu/version'
|
8
|
+
require 'tansu/context'
|
9
|
+
require 'tansu/response'
|
10
|
+
require 'tansu/render'
|
11
|
+
require 'tansu/environment'
|
12
|
+
require 'tansu/configuration'
|
13
|
+
require 'tansu/application'
|
14
|
+
require 'tansu/static'
|
13
15
|
|
14
16
|
module Tansu
|
15
17
|
class << self
|
data/tansu.gemspec
CHANGED
@@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
17
|
f.match(%r{^(test|spec|features)/})
|
18
18
|
end
|
19
|
-
spec.
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
21
|
spec.require_paths = ["lib"]
|
21
22
|
|
22
23
|
spec.add_dependency "rack"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tansu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- daisuko
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -125,9 +125,7 @@ dependencies:
|
|
125
125
|
description:
|
126
126
|
email:
|
127
127
|
- striker.daisuko@gmail.com
|
128
|
-
executables:
|
129
|
-
- console
|
130
|
-
- setup
|
128
|
+
executables: []
|
131
129
|
extensions: []
|
132
130
|
extra_rdoc_files: []
|
133
131
|
files:
|
@@ -147,6 +145,7 @@ files:
|
|
147
145
|
- lib/tansu/environment.rb
|
148
146
|
- lib/tansu/render.rb
|
149
147
|
- lib/tansu/response.rb
|
148
|
+
- lib/tansu/static.rb
|
150
149
|
- lib/tansu/version.rb
|
151
150
|
- tansu.gemspec
|
152
151
|
homepage: https://github.com/daisuko/tansu
|