rack-app 3.0.0 → 3.1.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.rb +1 -0
- data/lib/rack/app/endpoint.rb +1 -8
- data/lib/rack/app/middlewares.rb +3 -0
- data/lib/rack/app/middlewares/header_setter.rb +24 -0
- data/lib/rack/app/singleton_methods/inheritance.rb +0 -1
- data/lib/rack/app/singleton_methods/route_handling.rb +0 -1
- data/lib/rack/app/singleton_methods/settings.rb +5 -3
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61fb1f8227a3ca529ee22caefa0d7bc8e5b46993
|
4
|
+
data.tar.gz: 3c7bdc49faff05050c558f98d22919cf14f1ae22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f081f2de5494f5b2730a85722bc4eeeb2df25dbd16cae9d9ce01842ed5c085877dfd1b258e68898bf452999c212ea80630f25f75adf34647dc7321e7b9bc0944
|
7
|
+
data.tar.gz: 28684ea25e3c2a78370ebd696622a340a7d0dbb6303f2d051103ea8aa3f1f94f0325c6e8c8c35c2c448fbb055b2a6009aff2a36e8a22359e34c25ebabcef7767
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.0
|
data/lib/rack/app.rb
CHANGED
data/lib/rack/app/endpoint.rb
CHANGED
@@ -10,7 +10,6 @@ class Rack::App::Endpoint
|
|
10
10
|
@app_class = properties[:app_class]
|
11
11
|
@error_handler = properties[:error_handler] || Rack::App::ErrorHandler.new
|
12
12
|
@serializer = properties[:serializer] || Rack::App::Serializer.new
|
13
|
-
@headers = properties[:default_headers] || {}
|
14
13
|
|
15
14
|
@middleware = (properties[:middleware] || Rack::Builder.new).dup
|
16
15
|
@middleware.run(lambda { |env| self.execute(env) })
|
@@ -38,9 +37,9 @@ class Rack::App::Endpoint
|
|
38
37
|
def get_response_body(rack_request, rack_response)
|
39
38
|
|
40
39
|
request_handler = @app_class.new
|
41
|
-
set_default_headers(rack_response)
|
42
40
|
request_handler.request = rack_request
|
43
41
|
request_handler.response = rack_response
|
42
|
+
|
44
43
|
rack_request.env[::Rack::App::Constants::PATH_PARAMS_MATCHER]= @path_params_matcher.dup
|
45
44
|
return @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name)
|
46
45
|
|
@@ -59,12 +58,6 @@ class Rack::App::Endpoint
|
|
59
58
|
response.write(String(@serializer.serialize(result)))
|
60
59
|
end
|
61
60
|
|
62
|
-
def set_default_headers(response)
|
63
|
-
@headers.each do |header, value|
|
64
|
-
response.header[header]=value
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
61
|
def register_method_to_app_class(proc)
|
69
62
|
method_name = ::Rack::App::Utils.uuid
|
70
63
|
@app_class.__send__(:define_method, method_name, &proc)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Rack::App::Middlewares::HeaderSetter
|
2
|
+
|
3
|
+
def initialize(app, headers)
|
4
|
+
@app = app
|
5
|
+
@headers = headers.freeze
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
response = rack_response(@app.call(env))
|
10
|
+
|
11
|
+
@headers.each do |header, value|
|
12
|
+
response.headers[header] ||= value
|
13
|
+
end
|
14
|
+
|
15
|
+
response.finish
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def rack_response(raw_response)
|
21
|
+
Rack::Response.new(raw_response[2], raw_response[0], raw_response[1])
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -19,9 +19,11 @@ module Rack::App::SingletonMethods::Settings
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def headers(new_headers=nil)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
middleware do |b|
|
23
|
+
b.use(Rack::App::Middlewares::HeaderSetter,new_headers)
|
24
|
+
end if new_headers.is_a?(Hash)
|
25
|
+
|
26
|
+
new_headers
|
25
27
|
end
|
26
28
|
|
27
29
|
def error(*exception_classes, &block)
|
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: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -106,6 +106,8 @@ files:
|
|
106
106
|
- lib/rack/app/instance_methods/http_control.rb
|
107
107
|
- lib/rack/app/instance_methods/payload.rb
|
108
108
|
- lib/rack/app/instance_methods/upload.rb
|
109
|
+
- lib/rack/app/middlewares.rb
|
110
|
+
- lib/rack/app/middlewares/header_setter.rb
|
109
111
|
- lib/rack/app/params.rb
|
110
112
|
- lib/rack/app/request_configurator.rb
|
111
113
|
- lib/rack/app/router.rb
|