http1: added #consume; also, handling better 'connection: close' : if there were requests in-flight, assume that pipeline failed, and cap the concurrent number of requests to 1; this will disable pipelining, although the keep-alive header will still be sent

This commit is contained in:
HoneyryderChuck 2017-12-12 21:30:32 +00:00
parent 031d25fd02
commit 662be789ff

View File

@ -82,9 +82,23 @@ module HTTPX
emit(:response, request, response)
send(@pending.shift) unless @pending.empty?
return unless response.headers["connection"] == "close"
log { "connection closed" }
emit(:close)
if response.headers["connection"] == "close"
unless @requests.empty?
@requests.map { |r| r.transition(:idle) }
# server doesn't handle pipelining, and probably
# doesn't support keep-alive. Fallback to send only
# 1 keep alive request.
@max_concurrent_requests = 1
end
log { "connection: close" }
emit(:close)
end
end
def consume
@requests.each do |request|
handle(request)
end
end
private