def request req, body=nil, &block
resp = data = auth_data = nil
old_request req, body do |resp|
unless Net::HTTPUnauthorized === resp and auth_data = req.auth_data and
auth_data[0] == :ntlm and resp['www-authenticate'] == '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
resp = challenge.response({:user => auth_data[1], :password => auth_data[2]}, {:ntlmv2 => true})
req['Authorization'] = 'NTLM ' + resp.encode64
old_request(req, body) { |resp| yield resp if block_given? }
resp
end
end