lib/httpx/session.rb in httpx-1.3.0 vs lib/httpx/session.rb in httpx-1.3.1
- old
+ new
@@ -123,10 +123,11 @@
set_connection_callbacks(connection, connections, options)
end
connection
end
+ # sends the +request+ to the corresponding HTTPX::Connection
def send_request(request, connections, options = request.options)
error = catch(:resolve_error) do
connection = find_connection(request, connections, options)
connection.send(request)
end
@@ -229,10 +230,18 @@
pool.init_connection(connection, options)
connection
end
end
+ def deactivate_connection(request, connections, options)
+ conn = connections.find do |c|
+ c.match?(request.uri, options)
+ end
+
+ pool.deactivate(conn) if conn
+ end
+
# sends an array of HTTPX::Request +requests+, returns the respective array of HTTPX::Response objects.
def send_requests(*requests)
connections = _send_requests(requests)
receive_requests(requests, connections)
end
@@ -259,10 +268,11 @@
request = requests.first
return responses unless request
catch(:coalesced) { pool.next_tick } until (response = fetch_response(request, connections, request.options))
+ request.emit(:complete, response)
responses << response
requests.shift
break if requests.empty?
@@ -272,17 +282,19 @@
# 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)
+ response = fetch_response(request, connections, request.options)
+ request.emit(:complete, response) if response
+ responses << response
end
break
end
responses
ensure
if @persistent
- pool.deactivate(connections)
+ pool.deactivate(*connections)
else
close(connections)
end
end
end