rack-app 2.0.0 → 2.1.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 -0
- data/VERSION +1 -1
- data/lib/rack/app/instance_methods.rb +9 -41
- data/lib/rack/app/instance_methods/core.rb +18 -0
- data/lib/rack/app/instance_methods/http_control.rb +11 -0
- data/lib/rack/app/instance_methods/payload.rb +29 -0
- data/lib/rack/app/instance_methods/upload.rb +11 -0
- data/lib/rack/app/test.rb +16 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcb9bbf91b7776d8c02a6c59f386ddb5893e68e9
|
4
|
+
data.tar.gz: a28f17db847b1242e62407da66beebe838ff7543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e291f4fda263c63f7bba524094789f8ae213cebe6c908453ed39fe8534b31a81d517539d15d0a01fa621213a3d33661ead8da980ca4aefb2d80cb69253b805e
|
7
|
+
data.tar.gz: 2a70f922341c3bda2209d1728d3e8021a5cd514177f03b4fd3454b6dce67e9d002595325d9e432f11b57063efc563cc6654306bda34f25af14ce74071ec95696
|
data/README.md
CHANGED
@@ -79,6 +79,8 @@ Yes, in fact it's already powering heroku hosted micro-services.
|
|
79
79
|
* made with performance in mind so your app don't lose time by your framework
|
80
80
|
* per endpoint middleware definitions
|
81
81
|
* you can define middleware stack before endpoints and it will only applied to them, similar like protected method workflow
|
82
|
+
* File Upload and file download in a efficient and elegant way with minimal memory consuming
|
83
|
+
* note that this is not only memory friendly way pure rack solution, but also 2x faster than the usualy solution which includes buffering in memory
|
82
84
|
|
83
85
|
## Usage
|
84
86
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
@@ -1,45 +1,13 @@
|
|
1
1
|
module Rack::App::InstanceMethods
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def response
|
14
|
-
@response || raise("response object is not set for #{self.class}")
|
15
|
-
end
|
16
|
-
|
17
|
-
def payload
|
18
|
-
@__payload__ ||= lambda {
|
19
|
-
return nil unless @request.body.respond_to?(:gets)
|
20
|
-
|
21
|
-
payload = ''
|
22
|
-
while chunk = @request.body.gets
|
23
|
-
payload << chunk
|
24
|
-
end
|
25
|
-
@request.body.rewind
|
26
|
-
|
27
|
-
return payload
|
28
|
-
}.call
|
29
|
-
end
|
30
|
-
|
31
|
-
def redirect_to(url)
|
32
|
-
url = "#{url}?#{request.env['QUERY_STRING']}" unless request.env['QUERY_STRING'].empty?
|
33
|
-
response.status = 301
|
34
|
-
response.headers.merge!({'Location' => url})
|
35
|
-
'See Ya!'
|
36
|
-
end
|
37
|
-
|
38
|
-
def serve_file(file_path)
|
39
|
-
raw_rack_resp = Rack::App::FileServer.serve_file(request.env, file_path)
|
40
|
-
response.headers.merge!(raw_rack_resp[1])
|
41
|
-
response.body = raw_rack_resp.last
|
42
|
-
return nil
|
43
|
-
end
|
3
|
+
require 'rack/app/instance_methods/core'
|
4
|
+
require 'rack/app/instance_methods/http_control'
|
5
|
+
require 'rack/app/instance_methods/payload'
|
6
|
+
require 'rack/app/instance_methods/upload'
|
7
|
+
|
8
|
+
include Rack::App::InstanceMethods::Core
|
9
|
+
include Rack::App::InstanceMethods::HttpControl
|
10
|
+
include Rack::App::InstanceMethods::Payload
|
11
|
+
include Rack::App::InstanceMethods::Upload
|
44
12
|
|
45
13
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rack::App::InstanceMethods::Core
|
2
|
+
|
3
|
+
attr_writer :request, :response
|
4
|
+
|
5
|
+
def params
|
6
|
+
@__params__ ||= Rack::App::Params.new(request.env).to_hash
|
7
|
+
end
|
8
|
+
|
9
|
+
def request
|
10
|
+
@request || raise("request object is not set for #{self.class}")
|
11
|
+
end
|
12
|
+
|
13
|
+
def response
|
14
|
+
@response || raise("response object is not set for #{self.class}")
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Rack::App::InstanceMethods::HttpControl
|
2
|
+
|
3
|
+
def redirect_to(url)
|
4
|
+
url = "#{url}?#{request.env['QUERY_STRING']}" unless request.env['QUERY_STRING'].empty?
|
5
|
+
response.status = 301
|
6
|
+
response.headers.merge!({'Location' => url})
|
7
|
+
'See Ya!'
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Rack::App::InstanceMethods::Payload
|
2
|
+
|
3
|
+
def payload_stream(&block)
|
4
|
+
return nil unless @request.body.respond_to?(:gets)
|
5
|
+
while chunk = request.body.gets
|
6
|
+
block.call(chunk)
|
7
|
+
end
|
8
|
+
request.body.rewind
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def payload
|
13
|
+
@__payload__ ||= lambda {
|
14
|
+
|
15
|
+
payload = ''
|
16
|
+
payload_stream { |chunk| payload << chunk }
|
17
|
+
return payload
|
18
|
+
|
19
|
+
}.call
|
20
|
+
end
|
21
|
+
|
22
|
+
def payload_to_file(file_path, file_mod='w')
|
23
|
+
File.open(file_path, file_mod) do |file|
|
24
|
+
payload_stream { |chunk| file.print(chunk) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
data/lib/rack/app/test.rb
CHANGED
@@ -58,8 +58,23 @@ module Rack::App::Test
|
|
58
58
|
properties = format_properties(raw_properties)
|
59
59
|
additional_headers = properties[:headers].reduce({}) { |m, (k, v)| m.merge("HTTP_#{k.to_s.gsub('-', '_').upcase}" => v.to_s) }
|
60
60
|
|
61
|
+
|
61
62
|
payload = raw_properties.delete(:payload)
|
62
|
-
|
63
|
+
|
64
|
+
io = case payload
|
65
|
+
|
66
|
+
when IO
|
67
|
+
payload
|
68
|
+
|
69
|
+
when String
|
70
|
+
StringIO.new(payload.to_s)
|
71
|
+
|
72
|
+
else
|
73
|
+
StringIO.new('')
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
additional_headers["rack.input"]= ::Rack::Lint::InputWrapper.new(io)
|
63
78
|
|
64
79
|
{
|
65
80
|
"REMOTE_ADDR" => "192.168.56.1",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -95,6 +95,10 @@ files:
|
|
95
95
|
- lib/rack/app/error_handler.rb
|
96
96
|
- lib/rack/app/file_server.rb
|
97
97
|
- lib/rack/app/instance_methods.rb
|
98
|
+
- lib/rack/app/instance_methods/core.rb
|
99
|
+
- lib/rack/app/instance_methods/http_control.rb
|
100
|
+
- lib/rack/app/instance_methods/payload.rb
|
101
|
+
- lib/rack/app/instance_methods/upload.rb
|
98
102
|
- lib/rack/app/params.rb
|
99
103
|
- lib/rack/app/request_configurator.rb
|
100
104
|
- lib/rack/app/router.rb
|