File: auth_challenge.rb

package info (click to toggle)
ruby-mechanize 2.7.6-1%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,480 kB
  • sloc: ruby: 11,380; makefile: 5; sh: 4
file content (65 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Mechanize::HTTP

  AuthChallenge = Struct.new :scheme, :params, :raw

  ##
  # A parsed WWW-Authenticate header

  class AuthChallenge

    ##
    # :attr_accessor: scheme
    #
    # The authentication scheme

    ##
    # :attr_accessor: params
    #
    # The authentication parameters

    ##
    # :method: initialize
    #
    # :call-seq:
    #   initialize(scheme = nil, params = nil)
    #
    # Creates a new AuthChallenge header with the given scheme and parameters

    ##
    # Retrieves +param+ from the params list

    def [] param
      params[param]
    end

    ##
    # Constructs an AuthRealm for this challenge

    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

    ##
    # The name of the realm for this challenge

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

    ##
    # The raw authentication challenge

    alias to_s raw

  end

end