Only do the custom decompression on mono.

This commit is contained in:
Taloth Saldono 2019-01-08 20:33:50 +01:00
parent 76212ef908
commit 567719e6c4
1 changed files with 15 additions and 8 deletions

View File

@ -26,10 +26,19 @@ 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);
@ -37,7 +46,6 @@ namespace NzbDrone.Common.Http.Dispatchers
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))