Skip to content

Commit

Permalink
Second potential fix issue #83: Infinite stuck.
Browse files Browse the repository at this point in the history
  • Loading branch information
grandsilence committed May 28, 2020
1 parent 1956dcb commit 8204c81
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions Leaf.xNet/~Http/HttpResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -978,19 +978,13 @@ private void ParseCookieFromHeader(string headerValue)
#region Загрузка тела сообщения

// ReSharper disable once ReturnTypeCanBeEnumerable.Local
private BytesWrapper[] GetMessageBodySource()
private IEnumerable<BytesWrapper> GetMessageBodySource()
{
bool isNonUtf8ContentEncoding =
_headers.ContainsKey("Content-Encoding") &&
// Yandex oauth fix
!string.Equals(_headers["Content-Encoding"], "utf-8", StringComparison.OrdinalIgnoreCase);

var result = isNonUtf8ContentEncoding
var result = _headers.ContainsKey("Content-Encoding") && _headers["Content-Encoding"].Equals("gzip", StringComparison.OrdinalIgnoreCase)
? GetMessageBodySourceZip()
: GetMessageBodySourceStd();

// It's a fix of response get stuck response issue #83: https://github.com/csharp-leaf/Leaf.xNet/issues/83
return result.ToArray();

return result; // .ToArray(); - it will break Chunked requests.
}

// Загрузка обычных данных.
Expand All @@ -1016,7 +1010,27 @@ private IEnumerable<BytesWrapper> GetMessageBodySourceZip()
return ReceiveMessageBody(GetZipStream(streamWrapper));
}

private static byte[] GetResponse(Stream stream)
{
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
return memoryStream.ToArray();
}
}

// Загрузка тела сообщения неизвестной длины.
private static IEnumerable<BytesWrapper> ReceiveMessageBody(Stream stream)
{
// It's a fix of response get stuck response issue #83: https://github.com/csharp-leaf/Leaf.xNet/issues/83
var bytesWrapper = new BytesWrapper();
var responseBytes = GetResponse(stream);
bytesWrapper.Value = responseBytes;
bytesWrapper.Length = responseBytes.Length;
return new[] { bytesWrapper };
}

/*
private IEnumerable<BytesWrapper> ReceiveMessageBody(Stream stream)
{
var bytesWrapper = new BytesWrapper();
Expand Down Expand Up @@ -1087,6 +1101,7 @@ private IEnumerable<BytesWrapper> ReceiveMessageBody(Stream stream)
yield return bytesWrapper;
}
}
*/

// Загрузка тела сообщения известной длины.
private IEnumerable<BytesWrapper> ReceiveMessageBody(long contentLength)
Expand Down

0 comments on commit 8204c81

Please sign in to comment.