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); }
public void ParseHeader(IList header) { this.BeginUpdate(); try { this.Clear(); HeaderFieldList fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, header, fieldList); this.InternalParseHeader(header, fieldList); StringCollectionEx ex = new StringCollectionEx(); foreach (HeaderField field in fieldList) { if (!this.knownFields.Contains(field.Name, true)) { ex.Add(field.Name + ": " + HeaderFieldList.GetHeaderFieldValue(header, field)); } } if (ex.Count > 0) { this.ExtraFields = ex.ToArray(); } } finally { this.EndUpdate(); } }
private HttpRequestItem CreateMultiPartItem(string header) { ClearDataStream(); string[] stringArray = StringUtils.GetStringArray(header); var fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, stringArray, fieldList); HttpRequestItem item = CreateItem(stringArray, fieldList); item.ParseHeader(stringArray, fieldList); return(item); }
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); } } }
public void GetResponseCookies(StringCollection responseHeader) { base.Clear(); HeaderFieldList fieldList = new HeaderFieldList(); HeaderFieldList.GetHeaderFieldList(0, responseHeader, fieldList); if (!StringUtils.IsEmpty(HeaderFieldList.GetHeaderFieldValue(responseHeader, fieldList, "set-cookie2"))) { this.ProcessCookies(responseHeader, fieldList, "set-cookie2"); } else { this.ProcessCookies(responseHeader, fieldList, "set-cookie"); } }
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(""); }