mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
unmerge channel to another on uncoalesce; push pending and failed requests which share the same uri to the newly created channel
This commit is contained in:
parent
1b4463a90f
commit
d301ce6ab5
@ -102,6 +102,19 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
|
||||
def unmerge(channel)
|
||||
@hostnames -= channel.instance_variable_get(:@hostnames)
|
||||
[@parser.pending, @pending].each do |pending|
|
||||
pending.reject! do |request|
|
||||
request.uri == channel.uri && begin
|
||||
request.transition(:idle)
|
||||
channel.send(request)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def match?(uri)
|
||||
return false if @state == :closing
|
||||
|
||||
|
@ -56,16 +56,22 @@ module HTTPX
|
||||
|
||||
def find_channel(request, **options)
|
||||
uri = URI(request.uri)
|
||||
@connection.find_channel(uri) || begin
|
||||
channel = @connection.build_channel(uri, **options)
|
||||
set_channel_callbacks(channel)
|
||||
channel
|
||||
@connection.find_channel(uri) || build_channel(uri, options)
|
||||
end
|
||||
|
||||
def set_channel_callbacks(channel, options)
|
||||
channel.on(:response, &method(:on_response))
|
||||
channel.on(:promise, &method(:on_promise))
|
||||
channel.on(:uncoalesce) do |uncoalesced_uri|
|
||||
other_channel = build_channel(uncoalesced_uri, options)
|
||||
channel.unmerge(other_channel)
|
||||
end
|
||||
end
|
||||
|
||||
def set_channel_callbacks(channel)
|
||||
channel.on(:response, &method(:on_response))
|
||||
channel.on(:promise, &method(:on_promise))
|
||||
def build_channel(uri, options)
|
||||
channel = @connection.build_channel(uri, **options)
|
||||
set_channel_callbacks(channel, options)
|
||||
channel
|
||||
end
|
||||
|
||||
def __build_reqs(*args, **options)
|
||||
|
@ -51,11 +51,13 @@ module HTTPX
|
||||
uri = URI(request.uri)
|
||||
proxy = proxy_params(uri)
|
||||
return super unless proxy
|
||||
@connection.find_channel(proxy) || begin
|
||||
channel = build_proxy_channel(proxy, **options)
|
||||
set_channel_callbacks(channel)
|
||||
channel
|
||||
end
|
||||
@connection.find_channel(proxy) || build_channel(proxy, options)
|
||||
end
|
||||
|
||||
def build_channel(proxy, options)
|
||||
channel = build_proxy_channel(proxy, **options)
|
||||
set_channel_callbacks(channel, options)
|
||||
channel
|
||||
end
|
||||
|
||||
def build_proxy_channel(proxy, **options)
|
||||
|
Loading…
x
Reference in New Issue
Block a user