class Net::HTTP

Public Instance Methods

request(req, body = nil) { |res| ... } click to toggle source
# 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'][%rNTLM (.*)/, 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
Also aliased as: request_without_ntlm_auth
request_without_ntlm_auth(req, body = nil, &block) click to toggle source
Alias for: request