From 1956dcb173cdc5cf8d61e34f2f9cce2390c49552 Mon Sep 17 00:00:00 2001 From: Grand Silence Date: Wed, 27 May 2020 22:16:34 +0300 Subject: [PATCH] Fix Infinite stuck #83 --- Leaf.xNet/~Http/HttpResponse.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Leaf.xNet/~Http/HttpResponse.cs b/Leaf.xNet/~Http/HttpResponse.cs index 3c871d8..9521c97 100644 --- a/Leaf.xNet/~Http/HttpResponse.cs +++ b/Leaf.xNet/~Http/HttpResponse.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.IO.Compression; +using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -976,16 +977,20 @@ private void ParseCookieFromHeader(string headerValue) #region Загрузка тела сообщения - private IEnumerable GetMessageBodySource() + // ReSharper disable once ReturnTypeCanBeEnumerable.Local + private BytesWrapper[] GetMessageBodySource() { - if (_headers.ContainsKey("Content-Encoding") && - !string.Equals(_headers["Content-Encoding"], - "utf-8", StringComparison.OrdinalIgnoreCase)) // Yandex oauth - { - return GetMessageBodySourceZip(); - } - - return GetMessageBodySourceStd(); + bool isNonUtf8ContentEncoding = + _headers.ContainsKey("Content-Encoding") && + // Yandex oauth fix + !string.Equals(_headers["Content-Encoding"], "utf-8", StringComparison.OrdinalIgnoreCase); + + var result = isNonUtf8ContentEncoding + ? 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(); } // Загрузка обычных данных.