lib/httpx/connection.rb in httpx-0.13.2 vs lib/httpx/connection.rb in httpx-0.14.0

- old
+ new

@@ -67,11 +67,11 @@ else transition(:idle) end @inflight = 0 - @keep_alive_timeout = options.timeout.keep_alive_timeout + @keep_alive_timeout = options.timeout[:keep_alive_timeout] @keep_alive_timer = nil self.addresses = options.addresses if options.addresses end @@ -127,11 +127,11 @@ def create_idle(options = {}) self.class.new(@type, @origin, @options.merge(options)) end def merge(connection) - @origins += connection.instance_variable_get(:@origins) + @origins |= connection.instance_variable_get(:@origins) connection.purge_pending do |req| send(req) end end @@ -236,13 +236,13 @@ end def timeout return @timeout if defined?(@timeout) - return @options.timeout.connect_timeout if @state == :idle + return @options.timeout[:connect_timeout] if @state == :idle - @options.timeout.operation_timeout + @options.timeout[:operation_timeout] end private def connect @@ -411,11 +411,11 @@ end parser.on(:exhausted) do emit(:exhausted) end parser.on(:origin) do |origin| - @origins << origin + @origins |= [origin] end parser.on(:close) do |force| transition(:closing) if force transition(:closed) @@ -441,19 +441,20 @@ case ex when MisdirectedRequestError emit(:misdirected, request) else response = ErrorResponse.new(request, ex, @options) + request.response = response request.emit(:response, response) end end end def transition(nextstate) case nextstate when :idle - @timeout = @current_timeout = @options.timeout.connect_timeout + @timeout = @current_timeout = @options.timeout[:connect_timeout] when :open return if @state == :closed total_timeout @@ -461,11 +462,11 @@ @io.connect return unless @io.connected? send_pending - @timeout = @current_timeout = @options.timeout.operation_timeout + @timeout = @current_timeout = @options.timeout[:operation_timeout] emit(:open) when :closing return unless @state == :open when :closed return unless @state == :closing @@ -540,15 +541,17 @@ end def handle_error(error) parser.handle_error(error) if @parser && parser.respond_to?(:handle_error) while (request = @pending.shift) - request.emit(:response, ErrorResponse.new(request, error, @options)) + response = ErrorResponse.new(request, error, @options) + request.response = response + request.emit(:response, response) end end def total_timeout - total = @options.timeout.total_timeout + total = @options.timeout[:total_timeout] return unless total @total_timeout ||= @timers.after(total) do ex = TotalTimeoutError.new(total, "Timed out after #{total} seconds")