lib/httpx/plugins/proxy.rb in httpx-0.18.6 vs lib/httpx/plugins/proxy.rb in httpx-0.18.7

- old
+ new

@@ -83,11 +83,11 @@ uri = URI(uri).find_proxy uris << uri if uri end uris end - options.proxy.merge(uri: @_proxy_uris.first) unless @_proxy_uris.empty? + { uri: @_proxy_uris.first } unless @_proxy_uris.empty? end def find_connection(request, connections, options) return super unless options.respond_to?(:proxy) @@ -107,12 +107,14 @@ def build_connection(uri, options) proxy = options.proxy return super unless proxy connection = options.connection_class.new("tcp", uri, options) - pool.init_connection(connection, options) - connection + catch(:coalesced) do + pool.init_connection(connection, options) + connection + end end def fetch_response(request, connections, options) response = super if response.is_a?(ErrorResponse) && @@ -179,15 +181,24 @@ return super unless @options.proxy super && @options.proxy == options.proxy end - # should not coalesce connections here, as the IP is the IP of the proxy - def coalescable?(*) + def coalescable?(connection) return super unless @options.proxy - false + if @io.protocol == "h2" && + @origin.scheme == "https" && + connection.origin.scheme == "https" && + @io.can_verify_peer? + # in proxied connections, .origin is the proxy ; Given names + # are stored in .origins, this is what is used. + origin = URI(connection.origins.first) + @io.verify_hostname(origin.host) + else + @origin == connection.origin + end end def send(request) return super unless @options.proxy return super unless connecting? @@ -232,10 +243,10 @@ when :connected transition(:open) end end - def transition(nextstate) + def handle_transition(nextstate) return super unless @options.proxy case nextstate when :closing # this is a hack so that we can use the super method