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
|
# File 'lib/ntlm/http.rb', line 20
def request(req, body = nil, &block)
unless req.ntlm_auth_params
return request_without_ntlm_auth(req, body, &block)
end
unless started?
start do
req.delete('connection')
return request(req, body, &block)
end
end
req['authorization'] = 'NTLM ' + NTLM.negotiate.to_base64
res = request_without_ntlm_auth(req, body)
challenge = res['www-authenticate'][/NTLM (.*)/, 1].unpack('m').first rescue nil
if challenge && res.code == '401'
user, domain, password = req.ntlm_auth_params
req['authorization'] = 'NTLM ' + NTLM.authenticate(challenge, user, domain, password).to_base64
req.body_stream.rewind if req.body_stream
request_without_ntlm_auth(req, body, &block) else
yield res if block_given?
res
end
end
|