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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54ad60f95e02d3a3d1cdd12869c110ebd8936c20
4
- data.tar.gz: 7acb5847ee8f8a9b12939572a316e0bd2e543b62
3
+ metadata.gz: 61fb1f8227a3ca529ee22caefa0d7bc8e5b46993
4
+ data.tar.gz: 3c7bdc49faff05050c558f98d22919cf14f1ae22
5
5
  SHA512:
6
- metadata.gz: 434df103635f1c9376d83c6736652337156e685ded88130846b62371beac56a3b9dd620e730e1dbe52c5127985d7247c223a8f515061b9c097dc8625339262cf
7
- data.tar.gz: 65712cce379e85a8183799f0d1aa0e37714c4e7e6642dce3005b83336812670afdaecd3f4431376d92f6f6d57d64e014a85ae7cce37a08c50da0c750a64d37c6
6
+ metadata.gz: f081f2de5494f5b2730a85722bc4eeeb2df25dbd16cae9d9ce01842ed5c085877dfd1b258e68898bf452999c212ea80630f25f75adf34647dc7321e7b9bc0944
7
+ data.tar.gz: 28684ea25e3c2a78370ebd696622a340a7d0dbb6303f2d051103ea8aa3f1f94f0325c6e8c8c35c2c448fbb055b2a6009aff2a36e8a22359e34c25ebabcef7767
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.0
@@ -15,6 +15,7 @@ class Rack::App
15
15
  require 'rack/app/endpoint'
16
16
  require 'rack/app/extension'
17
17
  require 'rack/app/serializer'
18
+ require 'rack/app/middlewares'
18
19
  require 'rack/app/file_server'
19
20
  require 'rack/app/error_handler'
20
21
  require 'rack/app/endpoint/not_found'
@@ -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,3 @@
1
+ module Rack::App::Middlewares
2
+ require 'rack/app/middlewares/header_setter'
3
+ end
@@ -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
@@ -11,7 +11,6 @@ module Rack::App::SingletonMethods::Inheritance
11
11
  def inherited(child)
12
12
 
13
13
  child.serializer(&serializer.logic)
14
- child.headers.merge!(headers)
15
14
  child.middlewares.push(*middlewares)
16
15
 
17
16
  on_inheritance.each do |block|
@@ -30,7 +30,6 @@ module Rack::App::SingletonMethods::RouteHandling
30
30
  :request_method => request_method,
31
31
  :request_path => request_path,
32
32
 
33
- :default_headers => headers,
34
33
  :error_handler => error,
35
34
  :description => @last_description,
36
35
  :serializer => serializer,
@@ -19,9 +19,11 @@ module Rack::App::SingletonMethods::Settings
19
19
  end
20
20
 
21
21
  def headers(new_headers=nil)
22
- @headers ||= {}
23
- @headers.merge!(new_headers) if new_headers.is_a?(Hash)
24
- @headers
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.0.0
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