mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-08 00:02:42 -04:00
client: allow to pass block to constructor; it keeps using the same connection
This commit is contained in:
parent
2b266d305d
commit
2bf6b21cad
@ -5,6 +5,15 @@ module HTTPX
|
||||
def initialize(**options)
|
||||
@default_options = self.class.default_options.merge(options)
|
||||
@connection = Connection.new(@default_options)
|
||||
if block_given?
|
||||
begin
|
||||
@keep_open = true
|
||||
yield self
|
||||
ensure
|
||||
@keep_open = false
|
||||
close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def close
|
||||
@ -13,8 +22,12 @@ module HTTPX
|
||||
|
||||
def request(verb, uri, **options)
|
||||
@default_options.request_class.new(verb, uri, **@default_options.merge(options))
|
||||
ensure
|
||||
close unless @keep_open
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def send(*requests)
|
||||
requests.each { |request| @connection << request }
|
||||
responses = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user