private bool Redirect(StringCollectionEx requestHeader, string[] responseText, ref string method) { string location = ResponseHeader.Location; var e = new HttpRedirectEventArgs(requestHeader.ToArray(), statusCode, ResponseHeader, responseText, method, false, false); string resourcePath = GetResourcePath(); OnRedirecting(e); method = e.Method; if (e.Handled || StringUtils.IsEmpty(location)) { return(e.CanRedirect); } url.Parse(Url.Url, location); if (StringUtils.IsEmpty(Url.AbsoluteUri)) { return(false); } method = GetRedirectMethod(StatusCode, method); if (GetResourcePath().IndexOf(resourcePath) != 0) { var fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Authorization"); } return(true); }
private void RemoveCookies(StringCollection requestHeader) { HeaderFieldList fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); for (int i = fieldList.Count - 1; i >= 0; i--) { HeaderField field = fieldList[i]; if (string.Compare(field.Name, "cookie", true, CultureInfo.InvariantCulture) == 0) { HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, field); } } }
private void PrepareRequestHeader(HttpTunnelStatus tunnelStatus, StringCollection requestHeader, Stream requestBody) { string str2; RemoveRequestLine(requestHeader); RemoveHeaderTrailer(requestHeader); string absolutePath = Url.AbsolutePath; if (IsUseProxy()) { switch (tunnelStatus) { case HttpTunnelStatus.None: absolutePath = Url.AbsoluteUri; break; case HttpTunnelStatus.Connect: absolutePath = string.Format("{0}:{1}", Url.Host, Url.Port); break; } } if (StringUtils.IsEmpty(absolutePath)) { absolutePath = "/"; } requestHeader.Insert(0, string.Format("{0} {1} {2}", method, absolutePath, httpVersions[(int)HttpVersion])); var fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Host"); fieldList.Clear(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); if (AllowCompression && StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "Accept-Encoding"))) { HeaderFieldList.AddHeaderField(requestHeader, "Accept-Encoding", "gzip, deflate"); } if (!StringUtils.IsEmpty(Url.Host)) { str2 = Url.Host + GetPortIfNeed(Url.Port); } else { str2 = base.Server + GetPortIfNeed(base.Port); } HeaderFieldList.AddHeaderField(requestHeader, "Host", str2); if (StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "User-Agent"))) { HeaderFieldList.AddHeaderField(requestHeader, "User-Agent", UserAgent); } string val = HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, "Content-Length"); if (requestBody.Length == 0L) { HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Content-Length"); fieldList.Clear(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); HeaderFieldList.RemoveHeaderField(requestHeader, fieldList, "Content-Type"); fieldList.Clear(); HeaderFieldList.GetHeaderFieldList(0, requestHeader, fieldList); } else if (StringUtils.IsEmpty(val) && ((tunnelStatus == HttpTunnelStatus.Connect) || (requestBody.Length > 0L))) { HeaderFieldList.AddHeaderField(requestHeader, "Content-Length", requestBody.Length.ToString()); } if (!AllowCaching && StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, cacheFields[(int)HttpVersion]))) { HeaderFieldList.AddHeaderField(requestHeader, cacheFields[(int)HttpVersion], "no-cache"); } if (KeepConnection && StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(requestHeader, fieldList, connFields[IsUseProxy() ? 1 : 0]))) { HeaderFieldList.AddHeaderField(requestHeader, connFields[IsUseProxy() ? 1 : 0], "Keep-Alive"); } if (AllowCookies) { Cookies.SetRequestCookies(requestHeader); } requestHeader.Add(""); }