From 567719e6c48324c9eca43e24dab6d79130b05b44 Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Tue, 8 Jan 2019 20:33:50 +0100 Subject: [PATCH] Only do the custom decompression on mono. --- .../Http/Dispatchers/ManagedHttpDispatcher.cs | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs b/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs index d9046eb55..3ae917eaf 100644 --- a/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs +++ b/src/NzbDrone.Common/Http/Dispatchers/ManagedHttpDispatcher.cs @@ -26,18 +26,26 @@ namespace NzbDrone.Common.Http.Dispatchers { var webRequest = (HttpWebRequest)WebRequest.Create((Uri)request.Url); - // Deflate is not a standard and could break depending on implementation. - // we should just stick with the more compatible Gzip - //http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net - webRequest.AutomaticDecompression = DecompressionMethods.None; - + if (PlatformInfo.IsMono) + { + // On Mono GZipStream/DeflateStream leaks memory if an exception is thrown, use an intermediate buffer in that case. + webRequest.AutomaticDecompression = DecompressionMethods.None; + webRequest.Headers.Add("Accept-Encoding", "gzip"); + } + else + { + // Deflate is not a standard and could break depending on implementation. + // we should just stick with the more compatible Gzip + //http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net + webRequest.AutomaticDecompression = DecompressionMethods.GZip; + } + webRequest.Method = request.Method.ToString(); webRequest.UserAgent = _userAgentBuilder.GetUserAgent(request.UseSimplifiedUserAgent); webRequest.KeepAlive = request.ConnectionKeepAlive; webRequest.AllowAutoRedirect = false; webRequest.CookieContainer = cookies; - webRequest.Headers.Add("Accept-Encoding", "gzip"); if (request.RequestTimeout != TimeSpan.Zero) { @@ -111,8 +119,7 @@ namespace NzbDrone.Common.Http.Dispatchers { data = responseStream.ToBytes(); - // Do our own decompression. - if (httpWebResponse.ContentEncoding == "gzip") + if (PlatformInfo.IsMono && httpWebResponse.ContentEncoding == "gzip") { using (var compressedStream = new MemoryStream(data)) using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))