From 8204c81cdd61a34e90931f639415f1f8a87a2280 Mon Sep 17 00:00:00 2001 From: Grand Silence Date: Thu, 28 May 2020 20:45:24 +0300 Subject: [PATCH] Second potential fix issue #83: Infinite stuck. --- Leaf.xNet/~Http/HttpResponse.cs | 35 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/Leaf.xNet/~Http/HttpResponse.cs b/Leaf.xNet/~Http/HttpResponse.cs index 9521c97..15cce17 100644 --- a/Leaf.xNet/~Http/HttpResponse.cs +++ b/Leaf.xNet/~Http/HttpResponse.cs @@ -978,19 +978,13 @@ private void ParseCookieFromHeader(string headerValue) #region Загрузка тела сообщения // ReSharper disable once ReturnTypeCanBeEnumerable.Local - private BytesWrapper[] GetMessageBodySource() + private IEnumerable 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. } // Загрузка обычных данных. @@ -1016,7 +1010,27 @@ private IEnumerable 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 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 ReceiveMessageBody(Stream stream) { var bytesWrapper = new BytesWrapper(); @@ -1087,6 +1101,7 @@ private IEnumerable ReceiveMessageBody(Stream stream) yield return bytesWrapper; } } + */ // Загрузка тела сообщения известной длины. private IEnumerable ReceiveMessageBody(long contentLength)