public bool CheckAuthorization (WebResponse response, HttpStatusCode code)
{
isCompleted = false;
if (code == HttpStatusCode.Unauthorized && request.credentials == null)
return false;
// FIXME: This should never happen!
if (isProxy != (code == HttpStatusCode.ProxyAuthenticationRequired))
return false;
if (isProxy && (request.proxy == null || request.proxy.Credentials == null))
return false;
string [] authHeaders = response.Headers.GetValues_internal (isProxy ? "Proxy-Authenticate" : "WWW-Authenticate", false);
if (authHeaders == null || authHeaders.Length == 0)
return false;
ICredentials creds = (!isProxy) ? request.credentials : request.proxy.Credentials;
Authorization auth = null;
foreach (string authHeader in authHeaders) {
auth = AuthenticationManager.Authenticate (authHeader, request, creds);
if (auth != null)
break;
}
if (auth == null)
return false;
request.webHeaders [isProxy ? "Proxy-Authorization" : "Authorization"] = auth.Message;
isCompleted = auth.Complete;
bool is_ntlm = (auth.Module.AuthenticationType == "NTLM");
if (is_ntlm)
ntlm_auth_state = (NtlmAuthState)((int) ntlm_auth_state + 1);
return true;
}