File tree 2 files changed +11
-4
lines changed
2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 25
25
module Async
26
26
module HTTP
27
27
module Faraday
28
- # Detect whether we can use persistent connections:
29
- PERSISTENT = ::Faraday ::Connection . instance_methods . include? ( :close )
30
-
31
28
class Adapter < ::Faraday ::Adapter
32
29
def initialize ( *arguments , **options , &block )
33
30
super
34
31
35
32
@internet = Async ::HTTP ::Internet . new
33
+ @persistent = ::Faraday ::Connection . instance_methods . include? ( :close ) && options . fetch ( :persistent , true )
36
34
end
37
35
38
36
def close
@@ -49,7 +47,7 @@ def call(env)
49
47
return @app . call ( env )
50
48
ensure
51
49
# Don't retain persistent connections unless they will eventually be closed:
52
- @internet . close unless PERSISTENT
50
+ @internet . close unless @persistent
53
51
end
54
52
end
55
53
end
Original file line number Diff line number Diff line change @@ -91,4 +91,13 @@ def get_response(url, path)
91
91
expect ( response . body ) . to be_nil
92
92
end
93
93
end
94
+
95
+ it 'closes connection automatically if persistent option is set to false' do
96
+ run_server ( Protocol ::HTTP ::Response [ 204 ] ) do
97
+ Faraday . new ( url : endpoint . url ) do |faraday |
98
+ faraday . response :logger
99
+ faraday . adapter :async_http , persistent : false
100
+ end . get ( '/index' )
101
+ end
102
+ end
94
103
end
You can’t perform that action at this time.
0 commit comments