async-http-faraday 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/http/faraday/adapter.rb +16 -6
- data/lib/async/http/faraday/agent.rb +34 -0
- data/lib/async/http/faraday/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6754e975558fbf1480ebf74ec990e82a8537751de269b054c7b7aea23b8a80db
|
4
|
+
data.tar.gz: bc0b9afcea1f32460f44dc45170c4de556a0549898ff8d80215cafbb47838856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 548a1b223ff55ee0e79a84004185c829ca9f1704da97ef62e0cb2345c82d83d324ca8eddc5f469b976a8ee3c5bf301bef94ad8564379e214b65fc103fba27bee
|
7
|
+
data.tar.gz: 8b70b6e79e179d6defcdeeb128e14ad90180aed8b15a0e6fedd831612e9221923ee092cb5b67d8b46327189ec4f2415c75e63747b3656eda0758ca31d982c2ab
|
@@ -20,8 +20,11 @@
|
|
20
20
|
|
21
21
|
require 'faraday'
|
22
22
|
require 'faraday/adapter'
|
23
|
+
require 'kernel/sync'
|
23
24
|
require 'async/http/internet'
|
24
25
|
|
26
|
+
require_relative 'agent'
|
27
|
+
|
25
28
|
module Async
|
26
29
|
module HTTP
|
27
30
|
module Faraday
|
@@ -57,10 +60,20 @@ module Async
|
|
57
60
|
def call(env)
|
58
61
|
super
|
59
62
|
|
60
|
-
|
61
|
-
response = @internet.call(env[:method].to_s.upcase, env[:url].to_s, env[:request_headers], env[:body] || [])
|
63
|
+
parent = Async::Task.current?
|
62
64
|
|
63
|
-
|
65
|
+
Sync do
|
66
|
+
with_timeout do
|
67
|
+
response = @internet.call(env[:method].to_s.upcase, env[:url].to_s, env[:request_headers], env[:body] || [])
|
68
|
+
|
69
|
+
save_response(env, response.status, response.read, response.headers)
|
70
|
+
end
|
71
|
+
ensure
|
72
|
+
# If we are the top level task, even if we are persistent, we must close the connection:
|
73
|
+
if parent.nil? || !@persistent
|
74
|
+
Async.logger.debug(self) {"Closing persistent connections."}
|
75
|
+
@internet.close
|
76
|
+
end
|
64
77
|
end
|
65
78
|
|
66
79
|
return @app.call(env)
|
@@ -70,9 +83,6 @@ module Async
|
|
70
83
|
raise ::Faraday::SSLError, e
|
71
84
|
rescue *CONNECTION_EXCEPTIONS => e
|
72
85
|
raise ::Faraday::ConnectionFailed, e
|
73
|
-
ensure
|
74
|
-
# Don't retain persistent connections unless they will eventually be closed:
|
75
|
-
@internet.close unless @persistent
|
76
86
|
end
|
77
87
|
|
78
88
|
private
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright, 2020, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
begin
|
22
|
+
require 'sawyer/agent'
|
23
|
+
|
24
|
+
# This is a nasty hack until https://github.com/lostisland/sawyer/pull/67 is resolved:
|
25
|
+
unless Sawyer::Agent.instance_methods.include?(:close)
|
26
|
+
class Sawyer::Agent
|
27
|
+
def close
|
28
|
+
@conn.close if @conn.respond_to?(:close)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue LoadError
|
33
|
+
# Ignore.
|
34
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-http-faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- examples/topics.rb
|
126
126
|
- lib/async/http/faraday.rb
|
127
127
|
- lib/async/http/faraday/adapter.rb
|
128
|
+
- lib/async/http/faraday/agent.rb
|
128
129
|
- lib/async/http/faraday/version.rb
|
129
130
|
homepage: https://github.com/socketry/async-http
|
130
131
|
licenses: []
|