mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-09 00:02:50 -04:00
track all new connections
This commit is contained in:
parent
7f055949af
commit
17ad340496
@ -104,7 +104,7 @@ module HTTPX
|
|||||||
connection = pool.find_connection(uri, proxy_options) || build_connection(uri, proxy_options)
|
connection = pool.find_connection(uri, proxy_options) || build_connection(uri, proxy_options)
|
||||||
unless connections.nil? || connections.include?(connection)
|
unless connections.nil? || connections.include?(connection)
|
||||||
connections << connection
|
connections << connection
|
||||||
set_connection_callbacks(connection, options)
|
set_connection_callbacks(connection, connections, options)
|
||||||
end
|
end
|
||||||
connection
|
connection
|
||||||
end
|
end
|
||||||
|
@ -60,22 +60,30 @@ module HTTPX
|
|||||||
connection = pool.find_connection(uri, options) || build_connection(uri, options)
|
connection = pool.find_connection(uri, options) || build_connection(uri, options)
|
||||||
unless connections.nil? || connections.include?(connection)
|
unless connections.nil? || connections.include?(connection)
|
||||||
connections << connection
|
connections << connection
|
||||||
set_connection_callbacks(connection, options)
|
set_connection_callbacks(connection, connections, options)
|
||||||
end
|
end
|
||||||
connection
|
connection
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_connection_callbacks(connection, options)
|
def set_connection_callbacks(connection, connections, options)
|
||||||
connection.on(:uncoalesce) do |uncoalesced_uri|
|
connection.on(:uncoalesce) do |uncoalesced_uri|
|
||||||
other_connection = build_connection(uncoalesced_uri, options)
|
other_connection = build_connection(uncoalesced_uri, options)
|
||||||
|
connections << other_connection
|
||||||
connection.unmerge(other_connection)
|
connection.unmerge(other_connection)
|
||||||
end
|
end
|
||||||
connection.on(:altsvc) do |alt_origin, origin, alt_params|
|
connection.on(:altsvc) do |alt_origin, origin, alt_params|
|
||||||
build_altsvc_connection(connection, alt_origin, origin, alt_params, options)
|
other_connection = build_altsvc_connection(connection, connections, alt_origin, origin, alt_params, options)
|
||||||
|
connections << other_connection if other_connection
|
||||||
|
end
|
||||||
|
connection.on(:exhausted) do
|
||||||
|
other_connection = connection.create_idle
|
||||||
|
other_connection.merge(connection)
|
||||||
|
pool.init_connection(other_connection, options)
|
||||||
|
connections << other_connection
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_altsvc_connection(existing_connection, alt_origin, origin, alt_params, options)
|
def build_altsvc_connection(existing_connection, connections, alt_origin, origin, alt_params, options)
|
||||||
altsvc = AltSvc.cached_altsvc_set(origin, alt_params.merge("origin" => alt_origin))
|
altsvc = AltSvc.cached_altsvc_set(origin, alt_params.merge("origin" => alt_origin))
|
||||||
|
|
||||||
# altsvc already exists, somehow it wasn't advertised, probably noop
|
# altsvc already exists, somehow it wasn't advertised, probably noop
|
||||||
@ -85,7 +93,7 @@ module HTTPX
|
|||||||
# advertised altsvc is the same origin being used, ignore
|
# advertised altsvc is the same origin being used, ignore
|
||||||
return if connection == existing_connection
|
return if connection == existing_connection
|
||||||
|
|
||||||
set_connection_callbacks(connection, options)
|
set_connection_callbacks(connection, connections, options)
|
||||||
|
|
||||||
log(level: 1) { "#{origin} alt-svc: #{alt_origin}" }
|
log(level: 1) { "#{origin} alt-svc: #{alt_origin}" }
|
||||||
|
|
||||||
@ -99,8 +107,10 @@ module HTTPX
|
|||||||
end
|
end
|
||||||
|
|
||||||
connection.merge(existing_connection)
|
connection.merge(existing_connection)
|
||||||
|
connection
|
||||||
rescue UnsupportedSchemeError
|
rescue UnsupportedSchemeError
|
||||||
altsvc["noop"] = true
|
altsvc["noop"] = true
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_requests(*args, options)
|
def build_requests(*args, options)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user