public HttpController(HttpWebRequest request) { if (request.PreAuthenticate) { this.http = HttpAuthState.Trying; } else { this.http = HttpAuthState.NoAuth; } this.proxy = HttpAuthState.NoAuth; redirections = 0; }
/* returns this WebRequest or a new one. * If nothing can be done, it will return the same 'ol * request. * Note: will change substantially soon*/ public WebRequest Recurse(HttpWebRequest request,HttpWebResponse response) { HttpStatusCode code=response.StatusCode; switch(code) { case HttpStatusCode.OK: { if(http==HttpAuthState.Trying) http=HttpAuthState.OK; if(proxy==HttpAuthState.Trying) proxy=HttpAuthState.OK; return request; } break; /* never reached */ case HttpStatusCode.ProxyAuthenticationRequired: { String challenge=null; if(proxy==HttpAuthState.Trying || proxy==HttpAuthState.Failed) { proxy=HttpAuthState.Failed; return request; } challenge=response.Headers["Proxy-Authenticate"]; request.ResetRequest(false); if(request.AddProxyAuthHeaders(challenge)) { request.ResetRequest(true); proxy=HttpAuthState.Trying; return request; } else { proxy=HttpAuthState.Failed; return request; } } break; case HttpStatusCode.Forbidden: { String challenge=null; if(http==HttpAuthState.Trying || http==HttpAuthState.Failed) { http=HttpAuthState.Failed; return request; } challenge=response.Headers["WWW-Authenticate"]; request.ResetRequest(false); if(request.AddHttpAuthHeaders(challenge)) { request.ResetRequest(true); http=HttpAuthState.Trying; return request; } else { http=HttpAuthState.Failed; return request; } } break; case HttpStatusCode.Redirect: case HttpStatusCode.Moved : case HttpStatusCode.MultipleChoices : case HttpStatusCode.SeeOther : case HttpStatusCode.TemporaryRedirect: /* case HttpStatusCode.Found : // Duplicate */ /* case HttpStatusCode.MovedPermanently : // Duplicate */ { Uri newUri=response.ResponseUri; if(request.allowAutoRedirect && newUri!=null && redirections<request.MaximumAutomaticRedirections && (request.Method=="GET" || request.Method=="HEAD")) { /* ok redirect it */ request.ResetRequest(true); request.SetAddress(newUri); redirections++; return request; } } break; } return request; }
public HttpController(HttpWebRequest request) { if(request.PreAuthenticate) { this.http=HttpAuthState.Trying; } else { this.http=HttpAuthState.NoAuth; } this.proxy=HttpAuthState.NoAuth; redirections=0; }
/* returns this WebRequest or a new one. * If nothing can be done, it will return the same 'ol * request. * Note: will change substantially soon*/ public WebRequest Recurse(HttpWebRequest request, HttpWebResponse response) { HttpStatusCode code = response.StatusCode; switch (code) { case HttpStatusCode.Continue: { // Drop this response so that real one can be read. request.response = null; return(request); } case HttpStatusCode.OK: { if (http == HttpAuthState.Trying) { http = HttpAuthState.OK; } if (proxy == HttpAuthState.Trying) { proxy = HttpAuthState.OK; } return(request); } break; /* never reached */ case HttpStatusCode.ProxyAuthenticationRequired: { String challenge = null; if (proxy == HttpAuthState.Trying || proxy == HttpAuthState.Failed) { proxy = HttpAuthState.Failed; return(request); } challenge = response.Headers["Proxy-Authenticate"]; request.ResetRequest(false); if (request.AddProxyAuthHeaders(challenge)) { request.ResetRequest(true); proxy = HttpAuthState.Trying; return(request); } else { proxy = HttpAuthState.Failed; return(request); } } break; case HttpStatusCode.Forbidden: { String challenge = null; if (http == HttpAuthState.Trying || http == HttpAuthState.Failed) { http = HttpAuthState.Failed; return(request); } challenge = response.Headers["WWW-Authenticate"]; request.ResetRequest(false); if (request.AddHttpAuthHeaders(challenge)) { request.ResetRequest(true); http = HttpAuthState.Trying; return(request); } else { http = HttpAuthState.Failed; return(request); } } break; case HttpStatusCode.Redirect: case HttpStatusCode.Moved: case HttpStatusCode.MultipleChoices: case HttpStatusCode.SeeOther: case HttpStatusCode.TemporaryRedirect: /* case HttpStatusCode.Found : // Duplicate */ /* case HttpStatusCode.MovedPermanently : // Duplicate */ { Uri newUri = response.ResponseUri; if (request.allowAutoRedirect && newUri != null && redirections < request.MaximumAutomaticRedirections && (request.Method == "GET" || request.Method == "HEAD")) { /* ok redirect it */ request.ResetRequest(true); request.SetAddress(newUri); redirections++; return(request); } } break; } return(request); }