lib/httpx/connection.rb in httpx-0.14.5 vs lib/httpx/connection.rb in httpx-0.15.0
- old
+ new
@@ -49,11 +49,11 @@
attr_writer :timers
def initialize(type, uri, options)
@type = type
@origins = [uri.origin]
- @origin = Utils.uri(uri.origin)
+ @origin = Utils.to_uri(uri.origin)
@options = Options.new(options)
@window_size = @options.window_size
@read_buffer = Buffer.new(BUFFER_SIZE)
@write_buffer = Buffer.new(BUFFER_SIZE)
@pending = []
@@ -252,10 +252,12 @@
def exhausted?
@parser && parser.exhausted?
end
def consume
+ return unless @io
+
catch(:called) do
epiped = false
loop do
parser.consume
@@ -309,11 +311,11 @@
# exit the read loop if connection is preparing to be closed
break if @state == :closing || @state == :closed
# exit #consume altogether if all outstanding requests have been dealt with
return if @pending.size.zero? && @inflight.zero?
- end unless (interests == :w || @state == :closing) && !epiped
+ end unless (interests.nil? || interests == :w || @state == :closing) && !epiped
#
# tight write loop.
#
# flush as many bytes as the sockets allow.
@@ -422,10 +424,13 @@
if force
transition(:closed)
emit(:close)
end
end
+ parser.on(:close_handshake) do
+ consume
+ end
parser.on(:reset) do
if parser.empty?
reset
else
transition(:closing)
@@ -434,10 +439,13 @@
@parser.reset if @parser
transition(:idle)
transition(:open)
end
end
+ parser.on(:current_timeout) do
+ @current_timeout = @timeout = parser.timeout
+ end
parser.on(:timeout) do |tout|
@timeout = tout
end
parser.on(:error) do |request, ex|
case ex
@@ -464,13 +472,14 @@
@io.connect
return unless @io.connected?
send_pending
- @timeout = @current_timeout = @options.timeout[:operation_timeout]
+ @timeout = @current_timeout = parser.timeout
emit(:open)
when :closing
return unless @state == :open
+
when :closed
return unless @state == :closing
return unless @write_buffer.empty?
if @total_timeout