mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-06 00:02:08 -04:00
options.merge: return the same object if the one being merged is empty
This commit is contained in:
parent
7d9c5a722e
commit
9f33518850
@ -146,8 +146,10 @@ module HTTPX
|
||||
end
|
||||
|
||||
def merge(other)
|
||||
h1 = to_hash
|
||||
h2 = other.to_hash
|
||||
return self if h2.empty?
|
||||
|
||||
h1 = to_hash
|
||||
|
||||
merged = h1.merge(h2) do |k, v1, v2|
|
||||
case k
|
||||
|
@ -5,7 +5,9 @@ module HTTPX
|
||||
include Loggable
|
||||
include Chainable
|
||||
|
||||
def initialize(options = {}, &blk)
|
||||
EMPTY_HASH = {}.freeze
|
||||
|
||||
def initialize(options = EMPTY_HASH, &blk)
|
||||
@options = self.class.default_options.merge(options)
|
||||
@responses = {}
|
||||
@persistent = @options.persistent
|
||||
@ -36,6 +38,14 @@ module HTTPX
|
||||
responses
|
||||
end
|
||||
|
||||
def build_request(verb, uri, options = EMPTY_HASH)
|
||||
rklass = @options.request_class
|
||||
request = rklass.new(verb, uri, @options.merge(options).merge(persistent: @persistent))
|
||||
request.on(:response, &method(:on_response).curry[request])
|
||||
request.on(:promise, &method(:on_promise))
|
||||
request
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def pool
|
||||
@ -122,8 +132,8 @@ module HTTPX
|
||||
requests = case args.size
|
||||
when 1
|
||||
reqs = args.first
|
||||
reqs.map do |verb, uri|
|
||||
build_request(verb, uri, request_options)
|
||||
reqs.map do |verb, uri, opts = EMPTY_HASH|
|
||||
build_request(verb, uri, request_options.merge(opts))
|
||||
end
|
||||
when 2, 3
|
||||
verb, uris = args
|
||||
|
Loading…
x
Reference in New Issue
Block a user