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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c109996bf4e1ac263d36167d2f090404defde07adf3be7471f175f5bdd279d22
4
- data.tar.gz: 7cdaaad412d469ac673dc85cf149ffdf7fcd593b859a2c891c23bde36c065e6b
3
+ metadata.gz: 6754e975558fbf1480ebf74ec990e82a8537751de269b054c7b7aea23b8a80db
4
+ data.tar.gz: bc0b9afcea1f32460f44dc45170c4de556a0549898ff8d80215cafbb47838856
5
5
  SHA512:
6
- metadata.gz: 40b5496840bec8a74b60adfb807e84c1f863b1dd6719c6406018617d57c4c9313b45e492e88a2e2d224c15abf7c19b7fd5c0a7ed75280622193850942b0f86c0
7
- data.tar.gz: 1d326fe89303b9e64ba5824d72d29bf063e5124a314238dce919c1ff75fb3f56926a633c00d2ce0d6f6fd5b656596febdb4e4670789593b8d9fd1e44395801b3
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
- with_timeout do
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
- save_response(env, response.status, response.read, response.headers)
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
@@ -21,7 +21,7 @@
21
21
  module Async
22
22
  module HTTP
23
23
  module Faraday
24
- VERSION = "0.7.1"
24
+ VERSION = "0.8.0"
25
25
  end
26
26
  end
27
27
  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.7.1
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-03-30 00:00:00.000000000 Z
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: []