internal async Task <MemoryStream> LoadBody() { if (_sourceBody == null) { if (Headers["Content-Encoding"] != null) { if (Headers["Transfer-Encoding"] != null) { _sourceBody = await ReceiveZipBody(true); } if (_sourceBody == null && ContentLength.HasValue) { _sourceBody = await ReceiveZipBody(false); } if (_sourceBody == null) { using (StreamWrapper streamWrapper = new StreamWrapper(_request.CommonStream, _content)) { using (Stream gZipStream = GetZipStream(streamWrapper)) _sourceBody = await ReceiveUnsizeBody(gZipStream); } } } if (_sourceBody == null && Headers["Transfer-Encoding"] != null) { _sourceBody = await ReceiveStandartBody(true); } if (_sourceBody == null && ContentLength.HasValue) { _sourceBody = await ReceiveStandartBody(false); } if (_sourceBody == null) { _sourceBody = await ReceiveUnsizeBody(_request.CommonStream); } if (_sourceBody != null) { _sourceBody.Position = 0; if (Body == null) { Body = CharacterSet.GetString(_sourceBody.ToArray(), 0, (int)_sourceBody.Length); } } } return(_sourceBody); }
public override string ToString() { if (HasError) { throw new InvalidOperationException(Resources.InvalidOperationException_HttpResponse_HasError); } if (MessageBodyLoaded) { return(string.Empty); } MemoryStream memoryStream = new MemoryStream((ContentLength != -1) ? ContentLength : 0); try { IEnumerable <BytesWraper> messageBodySource = GetMessageBodySource(); foreach (BytesWraper item in messageBodySource) { memoryStream.Write(item.Value, 0, item.Length); } } catch (Exception ex) { HasError = true; if (ex is IOException || ex is InvalidOperationException) { throw NewHttpException(Resources.HttpException_FailedReceiveMessageBody, ex); } throw; } if (ConnectionClosed()) { _request.Dispose(); } MessageBodyLoaded = true; return(CharacterSet.GetString(memoryStream.GetBuffer(), 0, (int)memoryStream.Length)); }