rack-app 7.6.1 → 7.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -3
- data/VERSION +1 -1
- data/lib/rack/app/file_server.rb +38 -12
- data/lib/rack/app/instance_methods/serve_file.rb +4 -4
- data/lib/rack/app/payload/parser/builder/formats.rb +12 -12
- data/lib/rack/app/singleton_methods/mounting.rb +2 -2
- data/lib/rack/app/streamer/scheduler/null.rb +2 -2
- data/rack-app.gemspec +0 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf6acb7c4c89bd038387d214bd7379ade393a3f0b48088f4b7542b6a0c6f05ca
|
4
|
+
data.tar.gz: e084eaa3c611498a98bbdb7cb1a8ccbcdc81cc893e1c08848a515db4b9e536f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '09f143bdb3a084226e0f51f9f8c471dff28b06ab99f4f52c0895abd3541673152ef3949f34711a5eb67fc53ce1544c0bfd0acf6d000b30cf803c5b28f96ce1c1'
|
7
|
+
data.tar.gz: 6667a98608f80d53984ec9147373e370edecec9b5b525b74c3ff0c354f0843ea685deb2b96b57cae354039f56b1d1ab8104ae20bb1cf884bfba98c36b741c537
|
data/README.md
CHANGED
@@ -33,9 +33,8 @@ when rack provides a finalized support for http2.
|
|
33
33
|
If you have an issue, I weekly check the issues tab,
|
34
34
|
answer and reply, or implement a fix for it.
|
35
35
|
|
36
|
-
Since the framework
|
37
|
-
I don't have to update the code base
|
38
|
-
because there are no integration problems.
|
36
|
+
Since the framework's only dependency is the `rack` gem,
|
37
|
+
I don't have to update the code base to often.
|
39
38
|
|
40
39
|
Cheers and Happy Coding!
|
41
40
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
7.
|
1
|
+
7.7.0
|
data/lib/rack/app/file_server.rb
CHANGED
@@ -1,10 +1,24 @@
|
|
1
1
|
class Rack::App::FileServer
|
2
|
+
attr_accessor :relative_file_paths
|
2
3
|
|
3
|
-
def
|
4
|
-
|
4
|
+
def self.serve_file(env, file_path)
|
5
|
+
dir_path = File.dirname(file_path)
|
6
|
+
basename = File.basename(file_path)
|
7
|
+
file_server = new(dir_path, map_relative_file_paths: false)
|
8
|
+
env = env.dup
|
9
|
+
env[::Rack::App::Constants::ENV::REQUEST_METHOD] = 'GET'
|
10
|
+
env[::Rack::App::Constants::ENV::PATH_INFO] = basename
|
11
|
+
file_server.call(env)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(root_folder, opts = {})
|
5
15
|
@root_folder = root_folder
|
6
|
-
@relative_file_paths =
|
16
|
+
@relative_file_paths = []
|
7
17
|
@rack_file_server = ::Rack::File.new(@root_folder, {})
|
18
|
+
|
19
|
+
if map_relative_file_paths?(opts)
|
20
|
+
map_relative_paths!
|
21
|
+
end
|
8
22
|
end
|
9
23
|
|
10
24
|
def call(env)
|
@@ -12,7 +26,7 @@ class Rack::App::FileServer
|
|
12
26
|
|
13
27
|
@relative_file_paths.each do |relative_file_path|
|
14
28
|
if path_info =~ /#{Regexp.escape(relative_file_path)}$/
|
15
|
-
env[::Rack::App::Constants::ENV::PATH_INFO]= relative_file_path
|
29
|
+
env[::Rack::App::Constants::ENV::PATH_INFO] = relative_file_path
|
16
30
|
break
|
17
31
|
end
|
18
32
|
end
|
@@ -20,19 +34,31 @@ class Rack::App::FileServer
|
|
20
34
|
@rack_file_server.call(env)
|
21
35
|
end
|
22
36
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
37
|
+
protected
|
38
|
+
|
39
|
+
def map_relative_file_paths?(opts = {})
|
40
|
+
unless opts.key?(:map_relative_file_paths)
|
41
|
+
return true
|
42
|
+
end
|
43
|
+
|
44
|
+
opts[:map_relative_file_paths]
|
29
45
|
end
|
30
46
|
|
31
|
-
|
47
|
+
def opts_set_defaults(opts)
|
48
|
+
unless opts.key?(:map_relative_file_paths)
|
49
|
+
opts[:map_relative_file_paths] = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def map_relative_paths!
|
54
|
+
@relative_file_paths = Dir.glob(File.join(@root_folder, '**', '*'))
|
55
|
+
.map { |file_path| file_path.sub(@root_folder, '') }
|
56
|
+
.sort_by { |str| str.length }
|
57
|
+
.reverse
|
58
|
+
end
|
32
59
|
|
33
60
|
def clean_path_info(env)
|
34
61
|
path_info = ::Rack::Utils.unescape(env[::Rack::App::Constants::ENV::PATH_INFO])
|
35
62
|
::Rack::Utils.clean_path_info(path_info)
|
36
63
|
end
|
37
|
-
|
38
64
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Rack::App::InstanceMethods::ServeFile
|
2
2
|
|
3
3
|
def serve_file(file_path)
|
4
|
-
|
5
|
-
response.status =
|
6
|
-
response.headers.merge!(
|
7
|
-
response.body =
|
4
|
+
rack_resp = Rack::App::FileServer.serve_file(request.env, file_path)
|
5
|
+
response.status = rack_resp[0]
|
6
|
+
response.headers.merge!(rack_resp[1])
|
7
|
+
response.body = rack_resp[2]
|
8
8
|
finish!
|
9
9
|
end
|
10
10
|
|
@@ -2,11 +2,11 @@ module Rack::App::Payload::Parser::Builder::Formats
|
|
2
2
|
extend(self)
|
3
3
|
|
4
4
|
JSON_CONTENT_TYPES = [
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
'application/json',
|
6
|
+
'application/x-javascript',
|
7
|
+
'text/javascript',
|
8
|
+
'text/x-javascript',
|
9
|
+
'text/x-json'
|
10
10
|
].freeze
|
11
11
|
|
12
12
|
JSON_PARSER = proc do |io|
|
@@ -28,9 +28,9 @@ module Rack::App::Payload::Parser::Builder::Formats
|
|
28
28
|
end
|
29
29
|
|
30
30
|
JSON_STREAM_CONTENT_TYPES = [
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
'application/jsonstream',
|
32
|
+
'application/stream+json',
|
33
|
+
'application/x-json-stream'
|
34
34
|
].freeze
|
35
35
|
|
36
36
|
JSON_STREAM_PARSER = proc do |io|
|
@@ -62,8 +62,8 @@ module Rack::App::Payload::Parser::Builder::Formats
|
|
62
62
|
# end
|
63
63
|
|
64
64
|
FORM_CONTENT_TYPES = [
|
65
|
-
|
66
|
-
|
65
|
+
'application/x-www-form-urlencoded',
|
66
|
+
# 'multipart/form-data'
|
67
67
|
].freeze
|
68
68
|
|
69
69
|
FORM_SEP_CHAR = '&'.freeze
|
@@ -76,7 +76,7 @@ module Rack::App::Payload::Parser::Builder::Formats
|
|
76
76
|
lambda do |form|
|
77
77
|
::Rack::Utils.parse_nested_query(form, FORM_SEP_CHAR)
|
78
78
|
end
|
79
|
-
|
79
|
+
end
|
80
80
|
|
81
81
|
NULL_END_CHAR = /#{"\u0000"}$/
|
82
82
|
|
@@ -102,7 +102,7 @@ module Rack::App::Payload::Parser::Builder::Formats
|
|
102
102
|
last_name = form_name
|
103
103
|
unless respond_to?(form_name)
|
104
104
|
raise(NotImplementedError, "unknown formatter: #{last_name}")
|
105
|
-
end
|
105
|
+
end
|
106
106
|
__send__ form_name, builder
|
107
107
|
end
|
108
108
|
end
|
@@ -46,8 +46,8 @@ module Rack::App::SingletonMethods::Mounting
|
|
46
46
|
nil
|
47
47
|
end
|
48
48
|
|
49
|
-
def serve_files_from(
|
50
|
-
file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(
|
49
|
+
def serve_files_from(dir_path, options={})
|
50
|
+
file_server = Rack::App::FileServer.new(Rack::App::Utils.expand_path(dir_path))
|
51
51
|
request_path = Rack::App::Utils.join(options[:to], Rack::App::Constants::PATH::MOUNT_POINT)
|
52
52
|
add_route(::Rack::App::Constants::HTTP::METHOD::ANY, request_path, file_server)
|
53
53
|
nil
|
data/rack-app.gemspec
CHANGED
@@ -21,9 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.license = 'Apache License 2.0'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler'
|
24
|
-
spec.add_development_dependency 'rake', '10.4.2'
|
25
24
|
spec.add_development_dependency 'rspec'
|
26
|
-
|
27
25
|
spec.add_dependency 'rack'
|
28
26
|
|
29
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 10.4.2
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 10.4.2
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,7 +197,7 @@ homepage: http://www.rack-app.com/
|
|
211
197
|
licenses:
|
212
198
|
- Apache License 2.0
|
213
199
|
metadata: {}
|
214
|
-
post_install_message:
|
200
|
+
post_install_message:
|
215
201
|
rdoc_options: []
|
216
202
|
require_paths:
|
217
203
|
- lib
|
@@ -227,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
213
|
version: '0'
|
228
214
|
requirements: []
|
229
215
|
rubygems_version: 3.0.3
|
230
|
-
signing_key:
|
216
|
+
signing_key:
|
231
217
|
specification_version: 4
|
232
218
|
summary: Minimalist rack application interface building framework.
|
233
219
|
test_files: []
|