lib/httpx/connection.rb in httpx-0.24.3 vs lib/httpx/connection.rb in httpx-0.24.4

- old
+ new

@@ -40,11 +40,11 @@ def_delegator :@io, :closed? def_delegator :@write_buffer, :empty? - attr_reader :type, :io, :origin, :origins, :state, :pending, :options + attr_reader :type, :io, :origin, :origins, :state, :pending, :options, :ssl_session attr_writer :timers attr_accessor :family @@ -104,10 +104,16 @@ (@origins.size == 1 || @origin == uri.origin || (@io.is_a?(SSL) && @io.verify_hostname(uri.host))) ) && @options == options ) || (match_altsvcs?(uri) && match_altsvc_options?(uri, options)) end + def expired? + return false unless @io + + @io.expired? + end + def mergeable?(connection) return false if @state == :closing || @state == :closed || !@io return false if exhausted? @@ -136,10 +142,16 @@ self.class.new(@type, @origin, @options.merge(options)) end def merge(connection) @origins |= connection.instance_variable_get(:@origins) + if connection.ssl_session + @ssl_session = connection.ssl_session + @io.session_new_cb do |sess| + @ssl_session = sess + end if @io + end connection.purge_pending do |req| send(req) end end @@ -278,10 +290,21 @@ return @options.timeout[:connect_timeout] if @state == :idle @options.timeout[:operation_timeout] end + def idling + purge_after_closed + @write_buffer.clear + transition(:idle) + @parser = nil if @parser + end + + def used? + @connected_at + end + def deactivate transition(:inactive) end def open? @@ -308,10 +331,13 @@ return unless @io catch(:called) do epiped = false loop do + # connection may have + return if @state == :idle + parser.consume # we exit if there's no more requests to process # # this condition takes into account: @@ -549,10 +575,11 @@ def handle_transition(nextstate) case nextstate when :idle @timeout = @current_timeout = @options.timeout[:connect_timeout] + @connected_at = nil when :open return if @state == :closed @io.connect emit(:tcp_open, self) if @io.state == :connected @@ -592,17 +619,26 @@ @read_buffer.clear remove_instance_variable(:@timeout) if defined?(@timeout) end def build_socket(addrs = nil) - transport_type = case @type - when "tcp" then TCP - when "ssl" then SSL - when "unix" then UNIX - else - raise Error, "unsupported transport (#{@type})" + case @type + when "tcp" + TCP.new(@origin, addrs, @options) + when "ssl" + SSL.new(@origin, addrs, @options) do |sock| + sock.ssl_session = @ssl_session + sock.session_new_cb do |sess| + @ssl_session = sess + + sock.ssl_session = sess + end + end + when "unix" + UNIX.new(@origin, addrs, @options) + else + raise Error, "unsupported transport (#{@type})" end - transport_type.new(@origin, addrs, @options) end def on_error(error) if error.instance_of?(TimeoutError)