Do our own decompression to workaround mono bug.

This commit is contained in:
Taloth Saldono 2018-12-25 00:22:35 +01:00
parent c14b339d80
commit 76212ef908
1 changed files with 18 additions and 1 deletions

View File

@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.IO.Compression;
using System.Net; using System.Net;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -28,7 +29,7 @@ namespace NzbDrone.Common.Http.Dispatchers
// Deflate is not a standard and could break depending on implementation. // Deflate is not a standard and could break depending on implementation.
// we should just stick with the more compatible Gzip // 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 //http://stackoverflow.com/questions/8490718/how-to-decompress-stream-deflated-with-java-util-zip-deflater-in-net
webRequest.AutomaticDecompression = DecompressionMethods.GZip; webRequest.AutomaticDecompression = DecompressionMethods.None;
webRequest.Method = request.Method.ToString(); webRequest.Method = request.Method.ToString();
webRequest.UserAgent = _userAgentBuilder.GetUserAgent(request.UseSimplifiedUserAgent); webRequest.UserAgent = _userAgentBuilder.GetUserAgent(request.UseSimplifiedUserAgent);
@ -36,6 +37,8 @@ namespace NzbDrone.Common.Http.Dispatchers
webRequest.AllowAutoRedirect = false; webRequest.AllowAutoRedirect = false;
webRequest.CookieContainer = cookies; webRequest.CookieContainer = cookies;
webRequest.Headers.Add("Accept-Encoding", "gzip");
if (request.RequestTimeout != TimeSpan.Zero) if (request.RequestTimeout != TimeSpan.Zero)
{ {
webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds); webRequest.Timeout = (int)Math.Ceiling(request.RequestTimeout.TotalMilliseconds);
@ -107,6 +110,20 @@ namespace NzbDrone.Common.Http.Dispatchers
try try
{ {
data = responseStream.ToBytes(); data = responseStream.ToBytes();
// Do our own decompression.
if (httpWebResponse.ContentEncoding == "gzip")
{
using (var compressedStream = new MemoryStream(data))
using (var gzip = new GZipStream(compressedStream, CompressionMode.Decompress))
using (var decompressedStream = new MemoryStream())
{
gzip.CopyTo(decompressedStream);
data = decompressedStream.ToArray();
}
httpWebResponse.Headers.Remove("Content-Encoding");
}
} }
catch (Exception ex) catch (Exception ex)
{ {