restify 0.1.0.1.b17 → 0.1.0.1.b18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/restify/adapter.rb +89 -38
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTY0OWIxYmVlNTE1NzRlZGE3M2QwMTkxNzVjOTJjY2QwMWNkMGNlYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTJkMTE4MzczOTg2N2VjOTY2MTQ4MzgxMDIzYmYwNjQ1NTM4OWIwYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjljMDFlY2MzMjI3OTg3ZTgyOTRhZWU5ZDE3M2RjMzE5M2JlOWZiYWU0NjI5
|
10
|
+
Mzk1MjVhNzU3MjJiZDEzN2JhODczYzY0MDI0N2ZmNjkwMTQ0NjM1YzViNjQ1
|
11
|
+
N2VjMjc5NmNmMGM1MTRhZTliYWM2ZTdhZTVlZmI0NjAxMjc2MWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjIyMWY3ZGEwY2I1N2I1MWZhYzljMWZiYTkxY2Q4Zjk1ZDJmNWQxMTZhOTUx
|
14
|
+
OGVlYTg3NzI3ZjViNWM2NDhiZTRkZDFlY2MzMzcxOGIzOWEwMTRmYjgyZDNl
|
15
|
+
OTI0MDdhOTI2MjU1MmQ3NWRmMmIzZjhmMjQ4NDU0ZWU4YzRhMWE=
|
data/lib/restify/adapter.rb
CHANGED
@@ -6,35 +6,103 @@ module Restify
|
|
6
6
|
module Adapter
|
7
7
|
#
|
8
8
|
class EM
|
9
|
+
class Connection
|
10
|
+
class << self
|
11
|
+
def open(uri)
|
12
|
+
connections[uri.origin] ||= new uri.origin
|
13
|
+
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
def connections
|
16
|
+
@connections ||= {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :origin
|
21
|
+
|
22
|
+
def initialize(origin)
|
23
|
+
@origin = origin
|
24
|
+
@pipeline = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def requests
|
28
|
+
@requests ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
def call(request, writer)
|
32
|
+
requests << [request, writer]
|
33
|
+
process_next if requests.size == 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def connection
|
37
|
+
@connection ||= EventMachine::HttpRequest.new(origin)
|
38
|
+
end
|
39
|
+
|
40
|
+
def pipeline?
|
41
|
+
@pipeline
|
42
|
+
end
|
43
|
+
|
44
|
+
def process_next
|
45
|
+
return if requests.empty?
|
46
|
+
|
47
|
+
request, writer = pipeline? ? requests.shift : requests.first
|
48
|
+
req = connection.send request.method.downcase,
|
49
|
+
keepalive: true,
|
50
|
+
redirects: 3,
|
51
|
+
path: request.uri.normalized_path,
|
52
|
+
query: request.uri.normalized_query,
|
53
|
+
body: request.body,
|
54
|
+
head: request.headers
|
55
|
+
|
56
|
+
# puts "REQUEST: #{request} #{pipeline? ? 'w/' : 'w/o'} pipelining"
|
57
|
+
|
58
|
+
req.callback do
|
59
|
+
# puts "SUCCESS: #{request}"
|
60
|
+
requests.shift unless pipeline?
|
61
|
+
|
62
|
+
writer.fulfill Response.new(
|
63
|
+
request,
|
64
|
+
req.response_header.status,
|
65
|
+
req.response_header,
|
66
|
+
req.response
|
67
|
+
)
|
68
|
+
|
69
|
+
if req.response_header['CONNECTION'] == 'close'
|
70
|
+
@connection = nil
|
71
|
+
@pipeline = false
|
29
72
|
end
|
30
73
|
|
31
|
-
|
32
|
-
|
74
|
+
process_next
|
75
|
+
end
|
76
|
+
|
77
|
+
req.errback do
|
78
|
+
# puts "ERROR: #{request}"
|
79
|
+
@connection = nil
|
80
|
+
|
81
|
+
if pipeline?
|
82
|
+
EventMachine.next_tick do
|
83
|
+
@pipeline = false
|
84
|
+
call request, writer
|
85
|
+
end
|
86
|
+
else
|
87
|
+
begin
|
88
|
+
raise RuntimeError.new \
|
89
|
+
"(#{req.response_header.status}) #{req.error}"
|
90
|
+
rescue => e
|
91
|
+
writer.reject e
|
92
|
+
end
|
33
93
|
end
|
34
94
|
end
|
35
95
|
end
|
36
96
|
end
|
37
97
|
|
98
|
+
def call(request)
|
99
|
+
Obligation.create do |writer|
|
100
|
+
next_tick do
|
101
|
+
Connection.open(request.uri).call(request, writer)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
38
106
|
private
|
39
107
|
|
40
108
|
def next_tick(&block)
|
@@ -52,23 +120,6 @@ module Restify
|
|
52
120
|
end
|
53
121
|
end unless EventMachine.reactor_running?
|
54
122
|
end
|
55
|
-
|
56
|
-
#
|
57
|
-
class ConnectionPool
|
58
|
-
class << self
|
59
|
-
#
|
60
|
-
def get(uri)
|
61
|
-
connections[uri.origin] ||= begin
|
62
|
-
EventMachine::HttpRequest.new(uri.origin)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
def connections
|
68
|
-
@connections ||= {}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
123
|
end
|
73
124
|
end
|
74
125
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.1.
|
4
|
+
version: 0.1.0.1.b18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Graichen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: obligation
|