lib/httpx/connection.rb in httpx-0.8.1 vs lib/httpx/connection.rb in httpx-0.8.2
- old
+ new
@@ -86,12 +86,10 @@
def match?(uri, options)
return false if @state == :closing || @state == :closed
return false if exhausted?
- return false if @keep_alive_timer && @keep_alive_timer.fires_in.negative?
-
(
(
@origins.include?(uri.origin) &&
# if there is more than one origin to match, it means that this connection
# was the result of coalescing. To prevent blind trust in the case where the
@@ -105,12 +103,10 @@
def mergeable?(connection)
return false if @state == :closing || @state == :closed || !@io
return false if exhausted?
- return false if @keep_alive_timer && @keep_alive_timer.fires_in.negative?
-
!(@io.addresses & connection.addresses).empty? && @options == connection.options
end
# coalescable connections need to be mergeable!
# but internally, #mergeable? is called before #coalescable?
@@ -227,12 +223,23 @@
end
def send(request)
if @parser && !@write_buffer.full?
request.headers["alt-used"] = @origin.authority if match_altsvcs?(request.uri)
+ if @keep_alive_timer
+ # when pushing a request into an existing connection, we have to check whether there
+ # is the possibility that the connection might have extended the keep alive timeout.
+ # for such cases, we want to ping for availability before deciding to shovel requests.
+ if @keep_alive_timer.fires_in.negative?
+ @pending << request
+ parser.ping
+ return
+ end
+
+ @keep_alive_timer.pause
+ end
@inflight += 1
- @keep_alive_timer.pause if @keep_alive_timer
parser.send(request)
else
@pending << request
end
end
@@ -359,10 +366,12 @@
end
parser.on(:altsvc) do |alt_origin, origin, alt_params|
emit(:altsvc, alt_origin, origin, alt_params)
end
+ parser.on(:pong, &method(:send_pending))
+
parser.on(:promise) do |request, stream|
request.emit(:promise, parser, stream)
end
parser.on(:exhausted) do
emit(:exhausted)
@@ -467,11 +476,11 @@
@keep_alive_timer.resume
@keep_alive_timer.reset
else
@keep_alive_timer = @timers.after(@keep_alive_timeout) do
unless @inflight.zero?
- log { "(#{object_id})) keep alive timeout expired, closing..." }
- reset
+ log { "(#{@origin}): keep alive timeout expired" }
+ parser.ping
end
end
end
end