parent
e96d05149c
commit
b0415299ca
|
@ -271,6 +271,18 @@ namespace NzbDrone.Common.Test.Http
|
|||
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]
|
||||
public void should_not_download_file_with_error()
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace NzbDrone.Common.Http.Dispatchers
|
|||
{
|
||||
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.
|
||||
webRequest.AutomaticDecompression = DecompressionMethods.None;
|
||||
|
@ -120,6 +120,13 @@ namespace NzbDrone.Common.Http.Dispatchers
|
|||
if (responseStream != null && responseStream != Stream.Null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request.ResponseStream != null)
|
||||
{
|
||||
// A target ResponseStream was specified, write to that instead.
|
||||
responseStream.CopyTo(request.ResponseStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
data = responseStream.ToBytes();
|
||||
|
||||
|
@ -136,6 +143,7 @@ namespace NzbDrone.Common.Http.Dispatchers
|
|||
httpWebResponse.Headers.Remove("Content-Encoding");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new WebException("Failed to read complete http response", ex, WebExceptionStatus.ReceiveFailure, httpWebResponse);
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace NzbDrone.Common.Http
|
|||
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);
|
||||
}
|
||||
|
@ -240,9 +240,12 @@ namespace NzbDrone.Common.Http
|
|||
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
||||
|
||||
var stopWatch = Stopwatch.StartNew();
|
||||
var webClient = new GZipWebClient();
|
||||
webClient.Headers.Add(HttpRequestHeader.UserAgent, _userAgentBuilder.GetUserAgent());
|
||||
webClient.DownloadFile(url, fileName);
|
||||
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
|
||||
{
|
||||
var request = new HttpRequest(url);
|
||||
request.ResponseStream = fileStream;
|
||||
var response = Get(request);
|
||||
}
|
||||
stopWatch.Stop();
|
||||
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
using NzbDrone.Common.Extensions;
|
||||
|
@ -43,6 +44,7 @@ namespace NzbDrone.Common.Http
|
|||
public bool StoreResponseCookie { get; set; }
|
||||
public TimeSpan RequestTimeout { get; set; }
|
||||
public TimeSpan RateLimit { get; set; }
|
||||
public Stream ResponseStream { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue