def parse www_authenticate
challenges = []
@scanner = StringScanner.new www_authenticate
while true do
break if @scanner.eos?
challenge = Mechanize::HTTP::AuthChallenge.new
scheme = auth_scheme
if scheme == 'Negotiate'
scan_comma_spaces
end
next unless scheme
challenge.scheme = scheme
space = spaces
if scheme == 'NTLM' then
if space then
challenge.params = @scanner.scan(/.*/)
end
challenges << challenge
next
end
next unless space
params = {}
while true do
pos = @scanner.pos
name, value = auth_param
unless name then
challenge.params = params
challenges << challenge
break if @scanner.eos?
@scanner.pos = pos
challenge = ''
break
else
params[name] = value
end
spaces
return nil unless ',' == @scanner.peek(1) or @scanner.eos?
@scanner.scan(/(, *)+/)
end
end
challenges
end