Class: HTTPX::Plugins::Proxy::Parameters

Inherits:
Object
  • Object
show all
Defined in:
lib/httpx/plugins/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri:, scheme: nil, username: nil, password: nil, **extra) ⇒ Parameters

Returns a new instance of Parameters.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/httpx/plugins/proxy.rb', line 61

def initialize(uri:, scheme: nil, username: nil, password: nil, **extra)
  @uri = uri.is_a?(URI::Generic) ? uri : URI(uri)
  @username = username || @uri.user
  @password = password || @uri.password

  return unless @username && @password

  scheme ||= case @uri.scheme
             when "socks5"
               @uri.scheme
             when "http", "https"
               "basic"
             else
               return
  end

  @scheme = scheme

  auth_scheme = scheme.to_s.capitalize

  require_relative "authentication/#{scheme}" unless defined?(Authentication) && Authentication.const_defined?(auth_scheme, false)

  @authenticator = Authentication.const_get(auth_scheme).new(@username, @password, **extra)
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



59
60
61
# File 'lib/httpx/plugins/proxy.rb', line 59

def password
  @password
end

#schemeObject (readonly)

Returns the value of attribute scheme.



59
60
61
# File 'lib/httpx/plugins/proxy.rb', line 59

def scheme
  @scheme
end

#uriObject (readonly)

Returns the value of attribute uri.



59
60
61
# File 'lib/httpx/plugins/proxy.rb', line 59

def uri
  @uri
end

#usernameObject (readonly)

Returns the value of attribute username.



59
60
61
# File 'lib/httpx/plugins/proxy.rb', line 59

def username
  @username
end

Instance Method Details

#==(other) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/httpx/plugins/proxy.rb', line 98

def ==(other)
  case other
  when Parameters
    @uri == other.uri &&
      @username == other.username &&
      @password == other.password &&
      @scheme == other.scheme
  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

#authenticate(*args) ⇒ Object



92
93
94
95
96
# File 'lib/httpx/plugins/proxy.rb', line 92

def authenticate(*args)
  return unless @authenticator

  @authenticator.authenticate(*args)
end

#can_authenticate?(*args) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
# File 'lib/httpx/plugins/proxy.rb', line 86

def can_authenticate?(*args)
  return false unless @authenticator

  @authenticator.can_authenticate?(*args)
end