From be0d779448c3aa4176e9881f117cb28200e44f13 Mon Sep 17 00:00:00 2001 From: Frank Riley Date: Wed, 6 Aug 2014 19:34:49 -0700 Subject: [PATCH] When running under mono, WebClient will sometimes return less data than it should. This causes the FetchFeedService to log errors because the XML received cannot be parsed. Setting the AutomaticDecompression property on the WebRequest fixes this issue. --- src/NzbDrone.Common/Http/HttpProvider.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Common/Http/HttpProvider.cs b/src/NzbDrone.Common/Http/HttpProvider.cs index 6b04cb548..b122b9464 100644 --- a/src/NzbDrone.Common/Http/HttpProvider.cs +++ b/src/NzbDrone.Common/Http/HttpProvider.cs @@ -22,6 +22,16 @@ namespace NzbDrone.Common.Http public class HttpProvider : IHttpProvider { + private class GZipWebClient : WebClient + { + protected override WebRequest GetWebRequest(Uri address) + { + HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + return request; + } + } + private readonly Logger _logger; public const string CONTENT_LENGTH_HEADER = "Content-Length"; @@ -49,7 +59,7 @@ namespace NzbDrone.Common.Http { try { - var client = new WebClient { Credentials = identity }; + var client = new GZipWebClient { Credentials = identity }; client.Headers.Add(HttpRequestHeader.UserAgent, _userAgent); return client.DownloadString(url); } @@ -107,7 +117,7 @@ namespace NzbDrone.Common.Http _logger.Debug("Downloading [{0}] to [{1}]", url, fileName); var stopWatch = Stopwatch.StartNew(); - var webClient = new WebClient(); + var webClient = new GZipWebClient(); webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgent); webClient.DownloadFile(url, fileName); stopWatch.Stop();