rack-delegate 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/rack/delegate.rb +5 -0
- data/lib/rack/delegate/configuration.rb +7 -1
- data/lib/rack/delegate/delegator.rb +3 -11
- data/lib/rack/delegate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 635459c3a9a6f8fdfef399b29e6a8a8958be8b59
|
4
|
+
data.tar.gz: 244bba8c0cdd81896e6bebdcb9e537638e45d50d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bae04109174577d7ace0e5af0c6e65d04a4d4bbe8e2d5a93bd634862511600d7c2228f2654e67753df1424102b1b22090321a6a30bfb8f4044616f18b5cafa5
|
7
|
+
data.tar.gz: ba625dcc76877fcff011d0db4896477ddd1e74d98bb723ff5f5210ec09fba57f9398b8c8c18ee2174b3af6fadbac789b02e9067e0c1dc89d1838d45222b3fd5f
|
data/lib/rack/delegate.rb
CHANGED
@@ -12,6 +12,11 @@ module Rack
|
|
12
12
|
autoload :Configuration, 'rack/delegate/configuration'
|
13
13
|
autoload :Dispatcher, 'rack/delegate/dispatcher'
|
14
14
|
|
15
|
+
class << self
|
16
|
+
attr_accessor :network_error_response
|
17
|
+
end
|
18
|
+
self.network_error_response = NetworkErrorResponse
|
19
|
+
|
15
20
|
def self.configure(&block)
|
16
21
|
dispatcher = Dispatcher.configure(&block)
|
17
22
|
|
@@ -14,10 +14,11 @@ module Rack
|
|
14
14
|
@constraints = []
|
15
15
|
@rewriter = Rewriter.new
|
16
16
|
@changer = Rewriter.new
|
17
|
+
@timeout = NetworkErrorResponse
|
17
18
|
end
|
18
19
|
|
19
20
|
def from(pattern, to:, constraints: nil)
|
20
|
-
action = Action.new(pattern, Delegator.new(to, @rewriter, @changer))
|
21
|
+
action = Action.new(pattern, Delegator.new(to, @rewriter, @changer, @timeout))
|
21
22
|
action = Rack::Timeout.new(action) if timeout?
|
22
23
|
|
23
24
|
constraints = Array(constraints).concat(@constraints)
|
@@ -40,6 +41,11 @@ module Rack
|
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
44
|
+
def timeout(response_object = nil, &block)
|
45
|
+
@timeout = response_object if response_object
|
46
|
+
@timeout = block if block
|
47
|
+
end
|
48
|
+
|
43
49
|
private
|
44
50
|
|
45
51
|
def constraints(*args, &block)
|
@@ -3,14 +3,11 @@ require 'timeout_errors'
|
|
3
3
|
module Rack
|
4
4
|
module Delegate
|
5
5
|
class Delegator
|
6
|
-
|
7
|
-
attr_accessor :network_error_response
|
8
|
-
end
|
9
|
-
|
10
|
-
def initialize(url, uri_rewriter, net_http_request_rewriter)
|
6
|
+
def initialize(url, uri_rewriter, net_http_request_rewriter, timeout_response)
|
11
7
|
@url = URI(url)
|
12
8
|
@uri_rewriter = uri_rewriter
|
13
9
|
@net_http_request_rewriter = net_http_request_rewriter
|
10
|
+
@timeout_response = timeout_response
|
14
11
|
end
|
15
12
|
|
16
13
|
def call(env)
|
@@ -23,8 +20,7 @@ module Rack
|
|
23
20
|
|
24
21
|
convert_to_rack_response(http_response)
|
25
22
|
rescue TimeoutErrors
|
26
|
-
|
27
|
-
network_error_response.call(env)
|
23
|
+
@timeout_response.call(env)
|
28
24
|
end
|
29
25
|
|
30
26
|
private
|
@@ -33,10 +29,6 @@ module Rack
|
|
33
29
|
[@url.host, @url.port, https: @url.scheme == 'https']
|
34
30
|
end
|
35
31
|
|
36
|
-
def network_error_response
|
37
|
-
self.class.network_error_response ||= NetworkErrorResponse
|
38
|
-
end
|
39
|
-
|
40
32
|
def convert_to_rack_response(http_response)
|
41
33
|
status = http_response.code
|
42
34
|
headers = normalize_headers_for(http_response)
|