rack-app 0.16.0 → 0.17.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: 41c94a79f13a4ee69c813a267eb6a637a955ccbd
4
- data.tar.gz: 48abde6b600e6a968b2c6dad2c72b821a7844bec
3
+ metadata.gz: 9db5bf57a1cc7db597b8f23aee6228a8d82412ef
4
+ data.tar.gz: d815b86a8348006082e616e1feccc6a2f4a90d2c
5
5
  SHA512:
6
- metadata.gz: 7f1f75dbcda528fd377cb77f61eac7f5bf26246ffa9b0e7ba20534eaa5517ee4dce7a3bc0c790285381fbf90319b013c724b11e0f165539b5b0ac0fef9c3cc60
7
- data.tar.gz: a187dda8b666fd342430facf104f4aeac8a124a5aa9253c3540d3b1964f48dc60a9b5c07095862a2e71641429d4fe45ad8b83ed5a510cc1eb34734e0fbc372f9
6
+ metadata.gz: da155363a4645977acaa3c49a6d5f5689919618b5ba4a4b25307ff6a8fa1405f3b731605dbd6e152087fdc5ad0a187a7dab7a6bb83f3e7966deba18b360b504f
7
+ data.tar.gz: 31e97114d7a842b112eb98e1f4e66e149a9b4b8484d118b6087e9ee3c26c916450473ab6bd6c47ad0bf2f212a24487b23a436f217cd7a3a1cdd6079d7aa7ddf4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.16.0
1
+ 0.17.0
@@ -64,11 +64,11 @@ class Rack::App
64
64
  def root(endpoint_path)
65
65
  options '/' do
66
66
  endpoint = self.class.router.fetch_endpoint('OPTIONS', Rack::App::Utils.normalize_path(endpoint_path))
67
- endpoint.execute(request.env)
67
+ endpoint.get_response_body(request,response)
68
68
  end
69
69
  get '/' do
70
70
  endpoint = self.class.router.fetch_endpoint('GET', Rack::App::Utils.normalize_path(endpoint_path))
71
- endpoint.execute(request.env)
71
+ endpoint.get_response_body(request,response)
72
72
  end
73
73
  end
74
74
 
@@ -2,6 +2,8 @@ class Rack::App::Endpoint
2
2
 
3
3
  attr_reader :properties
4
4
 
5
+ LAST_MODIFIED_HEADER = "Last-Modified".freeze
6
+
5
7
  def initialize(properties)
6
8
  @properties = properties
7
9
 
@@ -19,19 +21,20 @@ class Rack::App::Endpoint
19
21
  request = Rack::Request.new(request_env)
20
22
  response = Rack::Response.new
21
23
 
22
- add_default_headers(response)
23
- request_handler = @api_class.new
24
+ set_response_body(response, get_response_body(request, response))
24
25
 
25
- request_handler.request = request
26
- request_handler.response = response
27
- request.env['rack.app.path_params_matcher']= @path_params_matcher.dup
26
+ return response.finish
28
27
 
29
- call_return = @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name)
28
+ end
30
29
 
31
- return call_return if is_a_rack_response_finish?(call_return)
32
- add_response_body_if_missing(call_return, response)
30
+ def get_response_body(rack_request, rack_response)
33
31
 
34
- return response.finish
32
+ request_handler = @api_class.new
33
+ set_default_headers(rack_response)
34
+ request_handler.request = rack_request
35
+ request_handler.response = rack_response
36
+ rack_request.env['rack.app.path_params_matcher']= @path_params_matcher.dup
37
+ return @error_handler.execute_with_error_handling_for(request_handler, @endpoint_method_name)
35
38
 
36
39
  end
37
40
 
@@ -41,18 +44,20 @@ class Rack::App::Endpoint
41
44
 
42
45
  protected
43
46
 
44
- def add_response_body_if_missing(call_return, response)
45
- response.write(String(@serializer.serialize(call_return))) if response.body.empty?
46
- end
47
+ def set_response_body(response, result)
48
+ if result.is_a?(::Rack::App::File::Streamer)
49
+ response.length += result.length
50
+ response.headers[LAST_MODIFIED_HEADER]= result.mtime
51
+ response.body = result
47
52
 
48
- def is_a_rack_response_finish?(call_return)
49
- call_return.is_a?(Array) and
50
- call_return.length == 3 and
51
- call_return[0].is_a?(Integer) and
52
- call_return[1].is_a?(Hash)
53
+ else
54
+ response.write(String(@serializer.serialize(result)))
55
+
56
+ end
57
+ nil
53
58
  end
54
59
 
55
- def add_default_headers(response)
60
+ def set_default_headers(response)
56
61
  @headers.each do |header, value|
57
62
  response.header[header]=value
58
63
  end
@@ -2,8 +2,7 @@ app_class = Class.new(Rack::App)
2
2
  not_found_properties = {
3
3
  :user_defined_logic => lambda {
4
4
  response.status= 404
5
- response.write '404 Not Found'
6
- response.finish
5
+ return '404 Not Found'
7
6
  },
8
7
  :default_headers => {},
9
8
  :request_method => 'GET',
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: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-02-08 00:00:00.000000000 Z
12
+ date: 2016-02-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler