Method: Mechanize::HTTP::WWWAuthenticateParser#parse
- Defined in:
- lib/mechanize/http/www_authenticate_parser.rb
#parse(www_authenticate) ⇒ Object
Parsers the header. Returns an Array of challenges as strings
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/mechanize/http/www_authenticate_parser.rb', line 22 def parse www_authenticate challenges = [] @scanner = StringScanner.new www_authenticate while true do break if @scanner.eos? start = @scanner.pos challenge = Mechanize::HTTP::AuthChallenge.new scheme = auth_scheme if scheme == 'Negotiate' scan_comma_spaces end break unless scheme challenge.scheme = scheme space = spaces if scheme == 'NTLM' then if space then challenge.params = @scanner.scan(/.*/) end challenge.raw = www_authenticate[start, @scanner.pos] challenges << challenge next else scheme.capitalize! end next unless space params = {} while true do pos = @scanner.pos name, value = auth_param name.downcase! if name =~ /^realm$/i unless name then challenge.params = params challenges << challenge if @scanner.eos? then challenge.raw = www_authenticate[start, @scanner.pos] break end @scanner.pos = pos # rewind challenge.raw = www_authenticate[start, @scanner.pos].sub(/(,+)? *$/, '') challenge = nil # a token should be next, new challenge break else params[name] = value end spaces @scanner.scan(/(, *)+/) end end challenges end |