lib/httpx/connection/http1.rb in httpx-0.10.0 vs lib/httpx/connection/http1.rb in httpx-0.10.1
- old
+ new
@@ -19,10 +19,11 @@
@parser = Parser::HTTP1.new(self)
@buffer = buffer
@version = [1, 1]
@pending = []
@requests = []
+ @handshake_completed = false
end
def interests
# this means we're processing incoming response already
return :r if @request
@@ -153,10 +154,11 @@
end
@parser.reset!
@max_requests -= 1
manage_connection(response)
+
send(@pending.shift) unless @pending.empty?
end
def handle_error(ex)
if @pipelining
@@ -180,20 +182,31 @@
def manage_connection(response)
connection = response.headers["connection"]
case connection
when /keep-alive/i
+ if @handshake_completed
+ if @max_requests.zero?
+ @pending.concat(@requests)
+ @requests.clear
+ emit(:exhausted)
+ end
+ return
+ end
+
keep_alive = response.headers["keep-alive"]
return unless keep_alive
parameters = Hash[keep_alive.split(/ *, */).map do |pair|
pair.split(/ *= */)
end]
- @max_requests = parameters["max"].to_i if parameters.key?("max")
+ @max_requests = parameters["max"].to_i - 1 if parameters.key?("max")
+
if parameters.key?("timeout")
keep_alive_timeout = parameters["timeout"].to_i
emit(:timeout, keep_alive_timeout)
end
+ @handshake_completed = true
when /close/i
disable
when nil
# In HTTP/1.1, it's keep alive by default
return if response.version == "1.1"