Class: Net::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/ntlm/http.rb

Instance Method Summary collapse

Instance Method Details

#request(req, body = nil, &block) ⇒ Object



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

  # Negotiation
  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'
    # Authentication
    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)  # We must re-use the connection.
  else
    yield res if block_given?
    res
  end
end

#request_without_ntlm_authObject



17
# File 'lib/ntlm/http.rb', line 17

alias request_without_ntlm_auth request