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

- old
+ new

@@ -11,21 +11,22 @@ super || @state == :connecting || @state == :connected end private - def transition(nextstate) + def handle_transition(nextstate) return super unless @options.proxy && @options.proxy.uri.scheme == "http" case nextstate when :connecting return unless @state == :idle @io.connect return unless @io.connected? - @parser = ConnectProxyParser.new(@write_buffer, @options.merge(max_concurrent_requests: 1)) + @parser = registry(@io.protocol).new(@write_buffer, @options.merge(max_concurrent_requests: 1)) + @parser.extend(ProxyParser) @parser.once(:response, &method(:__http_on_connect)) @parser.on(:close) { transition(:closing) } __http_proxy_connect return if @state == :connected when :connected @@ -34,11 +35,11 @@ case @state when :connecting @parser.close @parser = nil when :idle - @parser = ProxyParser.new(@write_buffer, @options) + @parser.callbacks.clear set_parser_callbacks(@parser) end end super end @@ -52,11 +53,11 @@ if req.uri.scheme == "https" connect_request = ConnectRequest.new(req.uri, @options) @inflight += 1 parser.send(connect_request) else - transition(:connected) + handle_transition(:connected) end end def __http_on_connect(_, response) @inflight -= 1 @@ -74,37 +75,23 @@ reset end end end - class ProxyParser < Connection::HTTP1 - def headline_uri(request) - request.uri.to_s + module ProxyParser + def join_headline(request) + return super if request.verb == :connect + + "#{request.verb.to_s.upcase} #{request.uri} HTTP/#{@version.join(".")}" end def set_protocol_headers(request) extra_headers = super proxy_params = @options.proxy extra_headers["proxy-authorization"] = "Basic #{proxy_params.token_authentication}" if proxy_params.authenticated? extra_headers["proxy-connection"] = extra_headers.delete("connection") if extra_headers.key?("connection") extra_headers - end - end - - class ConnectProxyParser < ProxyParser - attr_reader :pending - - def headline_uri(request) - return super unless request.verb == :connect - - tunnel = request.path - log { "establishing HTTP proxy tunnel to #{tunnel}" } - tunnel - end - - def empty? - @requests.reject { |r| r.verb == :connect }.empty? || @requests.all? { |request| !request.response.nil? } end end class ConnectRequest < Request def initialize(uri, _options)