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
|
# File 'lib/net/ntlm_http.rb', line 51
def request req, body=nil, &block
resp = data = auth_data = nil
resp = old_request req, body do |resp|
wwwauth = resp.['www-authenticate'].split(",").collect{|x| x.strip} rescue ""
unless Net::HTTPUnauthorized === resp and auth_data = req.auth_data and
auth_data[0] == :ntlm and (wwwauth == 'NTLM' || wwwauth.is_a?(Array) && wwwauth.include?('NTLM')) ||
data = resp['www-authenticate'][/^NTLM (.*)/, 1]
data = false
yield resp if block_given?
end
end
return resp if data == false
req.reuse
unless data
req.ntlm_auth(*auth_data[1..2])
request req, body, &block
else
challenge = Net::NTLM::Message.decode64 data
domain,dummy,userid = auth_data[1].rpartition('\\')
resp = challenge.response({:domain=>domain, :user => userid, :password => auth_data[2]}, {:ntlmv2 => true})
req['Authorization'] = 'NTLM ' + resp.encode64
old_request(req, body) { |resp| yield resp if block_given? }
resp
end
end
|