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