rack-app 6.4.1 → 6.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/rack/app/endpoint.rb +1 -0
- data/lib/rack/app/endpoint/builder.rb +4 -0
- data/lib/rack/app/endpoint/catcher.rb +37 -0
- data/lib/rack/app/endpoint/executor.rb +6 -18
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dacbebee0057a6e067e03df4561ebee1c67a79f
|
4
|
+
data.tar.gz: 926b31b67476555c9a6f6fe63f6c8df8dcf1f9a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a4ec962ab5be3ba58699ec0bcd1d7224d934caf338bba4722ecab41dc28530135606addce7ddb1cb30ccff66d4f1888ba1379a881e065cbb936d353c7084f8
|
7
|
+
data.tar.gz: 9652a7ce5a607bb8ccd6d06d9b965bdc4f0ff40d7f438ad149ada21f1fac427d2674ce03e821454e5ca6871cf080cb6ff0fe05838307705eb518e2657d2e1ad1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
6.
|
1
|
+
6.5.0
|
data/lib/rack/app/endpoint.rb
CHANGED
@@ -28,10 +28,14 @@ class Rack::App::Endpoint::Builder
|
|
28
28
|
builder_block.call(builder)
|
29
29
|
end
|
30
30
|
builder.use(Rack::App::Middlewares::Configuration, @config)
|
31
|
+
|
31
32
|
apply_hook_middlewares(builder)
|
32
33
|
end
|
33
34
|
|
34
35
|
def apply_hook_middlewares(builder)
|
36
|
+
if @config.app_class.before.length + @config.app_class.after.length > 0
|
37
|
+
builder.use(Rack::App::Endpoint::Catcher, @config)
|
38
|
+
end
|
35
39
|
@config.app_class.before.each do |before_block|
|
36
40
|
builder.use(Rack::App::Middlewares::Hooks::Before, before_block)
|
37
41
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Rack::App::Endpoint::Catcher
|
2
|
+
|
3
|
+
def initialize(app, endpoint_properties)
|
4
|
+
@app = app
|
5
|
+
@endpoint_properties = endpoint_properties
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
handle_rack_response do
|
10
|
+
handle_response_body(env) do
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
protected
|
17
|
+
|
18
|
+
def handle_rack_response
|
19
|
+
catch(:rack_response) { return yield }.finish
|
20
|
+
end
|
21
|
+
|
22
|
+
def handle_response_body(env)
|
23
|
+
body = catch(:response_body) { return yield }
|
24
|
+
request_handler = env[Rack::App::Constants::ENV::HANDLER]
|
25
|
+
set_response_body(request_handler, body)
|
26
|
+
throw :rack_response, request_handler.response
|
27
|
+
end
|
28
|
+
|
29
|
+
EXTNAME = ::Rack::App::Constants::ENV::EXTNAME
|
30
|
+
|
31
|
+
def set_response_body(handler, response_body)
|
32
|
+
extname = handler.request.env[EXTNAME]
|
33
|
+
handler.response.headers.merge!(@endpoint_properties.serializer.response_headers_for(extname))
|
34
|
+
handler.response.write(@endpoint_properties.serializer.serialize(extname, response_body))
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -2,34 +2,22 @@ class Rack::App::Endpoint::Executor
|
|
2
2
|
|
3
3
|
def initialize(endpoint_properties)
|
4
4
|
@endpoint_properties = endpoint_properties
|
5
|
+
@catcher = Rack::App::Endpoint::Catcher.new(proc{ |env| execute(env) }, endpoint_properties)
|
5
6
|
end
|
6
7
|
|
7
8
|
def call(env)
|
8
|
-
|
9
|
+
@catcher.call(env)
|
9
10
|
end
|
10
11
|
|
11
12
|
protected
|
12
13
|
|
13
14
|
def execute(env)
|
14
|
-
|
15
|
-
|
16
|
-
return request_handler.response
|
15
|
+
resp = evaluate_value(env[Rack::App::Constants::ENV::HANDLER])
|
16
|
+
throw type(resp), resp
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
evaluated_value = evaluate_value(request_handler)
|
22
|
-
|
23
|
-
evaluated_value
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
EXTNAME = ::Rack::App::Constants::ENV::EXTNAME
|
28
|
-
|
29
|
-
def set_response_body(handler, response_body)
|
30
|
-
extname = handler.request.env[EXTNAME]
|
31
|
-
handler.response.headers.merge!(@endpoint_properties.serializer.response_headers_for(extname))
|
32
|
-
handler.response.write(@endpoint_properties.serializer.serialize(extname, response_body))
|
19
|
+
def type(resp)
|
20
|
+
resp.is_a?(Rack::Response) ? :rack_response : :response_body
|
33
21
|
end
|
34
22
|
|
35
23
|
def evaluate_value(request_handler)
|
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: 6.
|
4
|
+
version: 6.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/rack/app/constants/http_status_codes.rb
|
112
112
|
- lib/rack/app/endpoint.rb
|
113
113
|
- lib/rack/app/endpoint/builder.rb
|
114
|
+
- lib/rack/app/endpoint/catcher.rb
|
114
115
|
- lib/rack/app/endpoint/config.rb
|
115
116
|
- lib/rack/app/endpoint/executor.rb
|
116
117
|
- lib/rack/app/error_handler.rb
|