lib/httpx/plugins/proxy.rb in httpx-0.6.3 vs lib/httpx/plugins/proxy.rb in httpx-0.6.4

- old
+ new

@@ -3,10 +3,11 @@ require "resolv" require "ipaddr" require "forwardable" module HTTPX + HTTPProxyError = Class.new(Error) module Plugins # # This plugin adds support for proxies. It ships with support for: # # * HTTP proxies @@ -15,11 +16,11 @@ # * Socks5 proxies # # https://gitlab.com/honeyryderchuck/httpx/wikis/Proxy # module Proxy - Error = Class.new(Error) + Error = HTTPProxyError PROXY_ERRORS = [TimeoutError, IOError, SystemCallError, Error].freeze class Parameters attr_reader :uri, :username, :password @@ -32,17 +33,26 @@ def authenticated? @username && @password end def token_authentication - Base64.strict_encode64("#{user}:#{password}") + return unless authenticated? + + Base64.strict_encode64("#{@username}:#{@password}") end def ==(other) - if other.is_a?(Parameters) + case other + when Parameters @uri == other.uri && @username == other.username && @password == other.password + when URI::Generic, String + proxy_uri = @uri.dup + proxy_uri.user = @username + proxy_uri.password = @password + other_uri = other.is_a?(URI::Generic) ? other : URI.parse(other) + proxy_uri == other_uri else super end end end