Fixed: Download mediacover using configured proxy.

pull/38/head
Taloth Saldono 4 years ago committed by ta264
parent 3fa605177c
commit 138a188cc9

@ -278,6 +278,18 @@ namespace NzbDrone.Common.Test.Http
response.Resource.Headers[header].ToString().Should().Be(value); response.Resource.Headers[header].ToString().Should().Be(value);
} }
[Test]
public void should_download_file()
{
var file = GetTempFilePath();
var url = "https://sonarr.tv/img/slider/seriesdetails.png";
Subject.DownloadFile(url, file);
File.Exists(file).Should().BeTrue();
}
[Test] [Test]
public void should_not_download_file_with_error() public void should_not_download_file_with_error()
{ {

@ -32,7 +32,7 @@ namespace NzbDrone.Common.Http.Dispatchers
{ {
var webRequest = (HttpWebRequest)WebRequest.Create((Uri)request.Url); var webRequest = (HttpWebRequest)WebRequest.Create((Uri)request.Url);
if (PlatformInfo.IsMono) if (PlatformInfo.IsMono && request.ResponseStream == null)
{ {
// On Mono GZipStream/DeflateStream leaks memory if an exception is thrown, use an intermediate buffer in that case. // On Mono GZipStream/DeflateStream leaks memory if an exception is thrown, use an intermediate buffer in that case.
webRequest.AutomaticDecompression = DecompressionMethods.None; webRequest.AutomaticDecompression = DecompressionMethods.None;
@ -120,12 +120,20 @@ namespace NzbDrone.Common.Http.Dispatchers
{ {
try try
{ {
data = responseStream.ToBytes(); if (request.ResponseStream != null)
{
if (PlatformInfo.IsMono && httpWebResponse.ContentEncoding == "gzip") // A target ResponseStream was specified, write to that instead.
responseStream.CopyTo(request.ResponseStream);
}
else
{ {
data = data.Decompress(); data = responseStream.ToBytes();
httpWebResponse.Headers.Remove("Content-Encoding");
if (PlatformInfo.IsMono && httpWebResponse.ContentEncoding == "gzip")
{
data = data.Decompress();
httpWebResponse.Headers.Remove("Content-Encoding");
}
} }
} }
catch (Exception ex) catch (Exception ex)

@ -133,7 +133,7 @@ namespace NzbDrone.Common.Http
response = interceptor.PostResponse(response); response = interceptor.PostResponse(response);
} }
if (request.LogResponseContent) if (request.LogResponseContent && response.ResponseData != null)
{ {
_logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content); _logger.Trace("Response content ({0} bytes): {1}", response.ResponseData.Length, response.Content);
} }
@ -242,9 +242,19 @@ namespace NzbDrone.Common.Http
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName); _logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
var stopWatch = Stopwatch.StartNew(); var stopWatch = Stopwatch.StartNew();
var webClient = new GZipWebClient(); using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
webClient.Headers.Add(HttpRequestHeader.UserAgent, userAgent ?? _userAgentBuilder.GetUserAgent()); {
webClient.DownloadFile(url, fileName); var request = new HttpRequest(url);
if (userAgent.IsNotNullOrWhiteSpace())
{
request.Headers.Set("User-Agent", userAgent);
}
request.ResponseStream = fileStream;
var response = Get(request);
}
stopWatch.Stop(); stopWatch.Stop();
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds); _logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
} }

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Text; using System.Text;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
@ -42,6 +43,7 @@ namespace NzbDrone.Common.Http
public bool StoreResponseCookie { get; set; } public bool StoreResponseCookie { get; set; }
public TimeSpan RequestTimeout { get; set; } public TimeSpan RequestTimeout { get; set; }
public TimeSpan RateLimit { get; set; } public TimeSpan RateLimit { get; set; }
public Stream ResponseStream { get; set; }
public override string ToString() public override string ToString()
{ {

Loading…
Cancel
Save