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:
HoneyryderChuck 2018-09-20 14:25:05 +01:00
parent 1b4463a90f
commit d301ce6ab5
3 changed files with 33 additions and 12 deletions

View File

@ -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

View File

@ -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)

View File

@ -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)