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:, username: nil, password: nil) ⇒ Parameters

Returns a new instance of Parameters.



27
28
29
30
31
# File 'lib/httpx/plugins/proxy.rb', line 27

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

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



25
26
27
# File 'lib/httpx/plugins/proxy.rb', line 25

def password
  @password
end

#uriObject (readonly)

Returns the value of attribute uri.



25
26
27
# File 'lib/httpx/plugins/proxy.rb', line 25

def uri
  @uri
end

#usernameObject (readonly)

Returns the value of attribute username.



25
26
27
# File 'lib/httpx/plugins/proxy.rb', line 25

def username
  @username
end

Instance Method Details

#==(other) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/httpx/plugins/proxy.rb', line 43

def ==(other)
  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

#authenticated?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/httpx/plugins/proxy.rb', line 33

def authenticated?
  @username && @password
end

#token_authenticationObject



37
38
39
40
41
# File 'lib/httpx/plugins/proxy.rb', line 37

def token_authentication
  return unless authenticated?

  Base64.strict_encode64("#{@username}:#{@password}")
end