Class: Mechanize::HTTP::AuthChallenge

Inherits:
Struct
  • Object
show all
Defined in:
lib/mechanize/http/auth_challenge.rb,
lib/mechanize/http/auth_challenge.rb

Overview

A parsed WWW-Authenticate header

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



3
4
5
# File 'lib/mechanize/http/auth_challenge.rb', line 3

def params
  @params
end

#schemeObject

Returns the value of attribute scheme

Returns:

  • (Object)

    the current value of scheme



3
4
5
# File 'lib/mechanize/http/auth_challenge.rb', line 3

def scheme
  @scheme
end

Instance Method Details

#[](param) ⇒ Object

Retrieves param from the params list



28
29
30
# File 'lib/mechanize/http/auth_challenge.rb', line 28

def [] param
  params[param]
end

#realm(uri) ⇒ Object

Constructs an AuthRealm for this challenge



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/mechanize/http/auth_challenge.rb', line 35

def realm uri
  case scheme
  when 'Basic' then
    raise ArgumentError, "provide uri for Basic authentication" unless uri
    Mechanize::HTTP::AuthRealm.new scheme, uri + '/', self['realm']
  when 'Digest' then
    Mechanize::HTTP::AuthRealm.new scheme, uri + '/', self['realm']
  else
    raise Mechanize::Error, "unknown HTTP authentication scheme #{scheme}"
  end
end

#realm_nameObject

The name of the realm for this challenge



50
51
52
# File 'lib/mechanize/http/auth_challenge.rb', line 50

def realm_name
  params['realm'] if Hash === params # NTLM has a string for params
end

#to_sObject

The reconstructed, normalized challenge



57
58
59
60
61
# File 'lib/mechanize/http/auth_challenge.rb', line 57

def to_s
  auth_params = params.map { |name, value| "#{name}=\"#{value}\"" }

  "#{scheme} #{auth_params.join ', '}"
end