lib/httpx/session.rb in httpx-0.13.2 vs lib/httpx/session.rb in httpx-0.14.0
- old
+ new
@@ -75,26 +75,26 @@
end
connection
end
def set_connection_callbacks(connection, connections, options)
- connection.on(:misdirected) do |misdirected_request|
+ connection.only(:misdirected) do |misdirected_request|
other_connection = connection.create_idle(ssl: { alpn_protocols: %w[http/1.1] })
other_connection.merge(connection)
catch(:coalesced) do
pool.init_connection(other_connection, options)
end
set_connection_callbacks(other_connection, connections, options)
connections << other_connection
misdirected_request.transition(:idle)
other_connection.send(misdirected_request)
end
- connection.on(:altsvc) do |alt_origin, origin, alt_params|
+ connection.only(:altsvc) do |alt_origin, origin, alt_params|
other_connection = build_altsvc_connection(connection, connections, alt_origin, origin, alt_params, options)
connections << other_connection if other_connection
end
- connection.on(:exhausted) do
+ connection.only(:exhausted) do
other_connection = connection.create_idle
other_connection.merge(connection)
catch(:coalesced) do
pool.init_connection(other_connection, options)
end
@@ -173,30 +173,40 @@
connection
end
end
def send_requests(*requests, options)
- connections = []
request_options = @options.merge(options)
+ connections = _send_requests(requests, request_options)
+ receive_requests(requests, connections, request_options)
+ end
+
+ def _send_requests(requests, options)
+ connections = []
+
requests.each do |request|
error = catch(:resolve_error) do
- connection = find_connection(request, connections, request_options)
+ connection = find_connection(request, connections, options)
connection.send(request)
end
next unless error.is_a?(ResolveError)
request.emit(:response, ErrorResponse.new(request, error, options))
end
+ connections
+ end
+
+ def receive_requests(requests, connections, options)
responses = []
begin
# guarantee ordered responses
loop do
request = requests.first
- pool.next_tick until (response = fetch_response(request, connections, request_options))
+ pool.next_tick until (response = fetch_response(request, connections, options))
responses << response
requests.shift
break if requests.empty?
@@ -206,10 +216,10 @@
# in some cases, the pool of connections might have been drained because there was some
# handshake error, and the error responses have already been emitted, but there was no
# opportunity to traverse the requests, hence we're returning only a fraction of the errors
# we were supposed to. This effectively fetches the existing responses and return them.
while (request = requests.shift)
- responses << fetch_response(request, connections, request_options)
+ responses << fetch_response(request, connections, options)
end
break
end
responses
ensure