|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using NLog;
|
|
|
|
@ -35,19 +34,16 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
private readonly ICached<CookieContainer> _cookieContainerCache;
|
|
|
|
|
private readonly List<IHttpRequestInterceptor> _requestInterceptors;
|
|
|
|
|
private readonly IHttpDispatcher _httpDispatcher;
|
|
|
|
|
private readonly IUserAgentBuilder _userAgentBuilder;
|
|
|
|
|
|
|
|
|
|
public HttpClient(IEnumerable<IHttpRequestInterceptor> requestInterceptors,
|
|
|
|
|
ICacheManager cacheManager,
|
|
|
|
|
IRateLimitService rateLimitService,
|
|
|
|
|
IHttpDispatcher httpDispatcher,
|
|
|
|
|
IUserAgentBuilder userAgentBuilder,
|
|
|
|
|
Logger logger)
|
|
|
|
|
{
|
|
|
|
|
_requestInterceptors = requestInterceptors.ToList();
|
|
|
|
|
_rateLimitService = rateLimitService;
|
|
|
|
|
_httpDispatcher = httpDispatcher;
|
|
|
|
|
_userAgentBuilder = userAgentBuilder;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
|
|
|
|
ServicePointManager.DefaultConnectionLimit = 12;
|
|
|
|
@ -233,33 +229,7 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
|
|
|
|
|
public void DownloadFile(string url, string fileName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var fileInfo = new FileInfo(fileName);
|
|
|
|
|
if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
|
|
|
|
|
{
|
|
|
|
|
fileInfo.Directory.Create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
|
|
|
|
}
|
|
|
|
|
catch (WebException e)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn("Failed to get response from: {0} {1}", url, e.Message);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_logger.Warn(e, "Failed to get response from: " + url);
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
_httpDispatcher.DownloadFile(url, fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public HttpResponse Get(HttpRequest request)
|
|
|
|
|