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 void ReadCookies(StringCollectionEx responseHeader) { var cookies = new CookieList(); if (AllowCookies) { cookies.GetResponseCookies(responseHeader); } OnResponseReceived(new HttpResponseEventArgs(method, Url.Url, responseHeader.ToArray(), cookies)); }
public string[] Put(string url, Stream source) { Stream responseBody = new MemoryStream(); Put(url, source, responseBody); responseBody.Position = 0L; var ex = new StringCollectionEx(); ex.LoadFromStream(responseBody, ResponseHeader.CharSet); return(ex.ToArray()); }
public string[] Get(string url) { Stream destination = new MemoryStream(); Get(url, destination); destination.Position = 0L; var ex = new StringCollectionEx(); ex.LoadFromStream(destination, ResponseHeader.CharSet); return(ex.ToArray()); }
private string[] InternalSendRequest(string method, string[] requestHeader, Stream requestBody, Stream responseBody) { string[] strArray2; using (var stream = new MemoryStream()) { var ex = new StringCollectionEx(); if (requestHeader != null) { ex.AddRange(requestHeader); } var responseHeader = new StringCollectionEx(); this.method = method; if (requestBody == null) { requestBody = Stream.Null; } if (responseBody == null) { responseBody = Stream.Null; } string[] responseText = null; long position = requestBody.Position; bool flag = false; int num2 = 0; int num3 = 0; int num4 = 0; long extraSize = 0L; HttpTunnelStatus none = HttpTunnelStatus.None; try { while (true) { none = GetTunnelStatus(); WriteRequestHeader(none, ex, requestBody); requestBody.Position = position; WriteRequestData(requestBody); OnRequestSent(new HttpRequestEventArgs(this.method, Url.Url, ex.ToArray())); ReadResponseHeader(responseHeader, stream); extraSize = stream.Length - stream.Position; flag = !GetKeepAlive(); if ((((StatusCode / 100) == 3) && (StatusCode != 0x130)) && (StatusCode != 0x131)) { num2++; responseText = ReadResponseText(responseHeader, extraSize, stream); if ((MaxRedirects > 0) && (num2 > MaxRedirects)) { RaiseHttpError(StatusCode, responseHeader, responseText); } string str = this.method; if (!AllowRedirects || !Redirect(ex, responseText, ref str)) { RaiseHttpError(StatusCode, responseHeader, responseText); } if (string.Compare(str, "GET", true, CultureInfo.InvariantCulture) == 0) { requestBody = Stream.Null; } this.method = str; if (IsUseProxy()) { flag = true; } } else if (StatusCode == 0x191) { num3++; responseText = ReadResponseText(responseHeader, extraSize, stream); if ((MaxAuthRetries > 0) && (num3 > MaxAuthRetries)) { RaiseHttpError(StatusCode, responseHeader, responseText); } } else if (StatusCode == 0x197) { num4++; responseText = ReadResponseText(responseHeader, extraSize, stream); if ((MaxAuthRetries > 0) && (num4 > MaxAuthRetries)) { RaiseHttpError(StatusCode, responseHeader, responseText); } } else if (StatusCode >= 400) { responseText = ReadResponseText(responseHeader, extraSize, stream); RaiseHttpError(StatusCode, responseHeader, responseText); } else { ReadResponseBody(responseHeader, extraSize, stream, responseBody); goto Label_032C; } if (flag) { base.Close(); } } } finally { if (flag && (none != HttpTunnelStatus.Connect)) { base.Close(); } } Label_032C: strArray2 = responseHeader.ToArray(); } return(strArray2); }