mirror of https://github.com/lidarr/Lidarr
Fixed: Remove obsolete HttpProvider
This commit is contained in:
parent
32ced861a7
commit
2e127d721c
|
@ -1,46 +0,0 @@
|
|||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Http;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test
|
||||
{
|
||||
[TestFixture]
|
||||
public class WebClientTests : TestBase<HttpProvider>
|
||||
{
|
||||
[Test]
|
||||
public void DownloadString_should_be_able_to_dowload_text_file()
|
||||
{
|
||||
var jquery = Subject.DownloadString("http://www.google.com/robots.txt");
|
||||
|
||||
jquery.Should().NotBeNullOrWhiteSpace();
|
||||
jquery.Should().Contain("Sitemap");
|
||||
}
|
||||
|
||||
[TestCase("")]
|
||||
public void DownloadString_should_throw_on_empty_string(string url)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
// .net 4.6.2 throws NotSupportedException instead of ArgumentException here
|
||||
[TestCase("http://")]
|
||||
public void DownloadString_should_throw_on_not_supported_string_windows(string url)
|
||||
{
|
||||
WindowsOnly();
|
||||
Assert.Throws<NotSupportedException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[TestCase("http://")]
|
||||
public void DownloadString_should_throw_on_not_supported_string_mono(string url)
|
||||
{
|
||||
MonoOnly();
|
||||
Assert.Throws<System.Net.WebException>(() => Subject.DownloadString(url));
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Common.Http
|
||||
{
|
||||
[Obsolete("Use IHttpClient")]
|
||||
public interface IHttpProvider
|
||||
{
|
||||
string DownloadString(string url);
|
||||
string DownloadString(string url, string username, string password);
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Use HttpProvider")]
|
||||
public class HttpProvider : IHttpProvider
|
||||
{
|
||||
private readonly Logger _logger;
|
||||
|
||||
|
||||
private readonly string _userAgent;
|
||||
|
||||
public HttpProvider(Logger logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_userAgent = $"{BuildInfo.AppName}/{BuildInfo.Version.ToString(2)}";
|
||||
ServicePointManager.Expect100Continue = false;
|
||||
}
|
||||
|
||||
public string DownloadString(string url)
|
||||
{
|
||||
return DownloadString(url, null);
|
||||
}
|
||||
|
||||
public string DownloadString(string url, string username, string password)
|
||||
{
|
||||
return DownloadString(url, new NetworkCredential(username, password));
|
||||
}
|
||||
|
||||
private string DownloadString(string url, ICredentials identity)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = new GZipWebClient { Credentials = identity };
|
||||
client.Headers.Add(HttpRequestHeader.UserAgent, _userAgent);
|
||||
return client.DownloadString(url);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -25,7 +25,6 @@ namespace NzbDrone.Core.Test.Framework
|
|||
Mocker.SetConstant<IHttpProxySettingsProvider>(new HttpProxySettingsProvider(Mocker.Resolve<ConfigService>()));
|
||||
Mocker.SetConstant<ICreateManagedWebProxy>(new ManagedWebProxyFactory(Mocker.Resolve<CacheManager>()));
|
||||
Mocker.SetConstant<IHttpDispatcher>(new ManagedHttpDispatcher(Mocker.Resolve<IHttpProxySettingsProvider>(), Mocker.Resolve<ICreateManagedWebProxy>(), Mocker.Resolve<UserAgentBuilder>(), Mocker.Resolve<IPlatformInfo>(), TestLogger));
|
||||
Mocker.SetConstant<IHttpProvider>(new HttpProvider(TestLogger));
|
||||
Mocker.SetConstant<IHttpClient>(new HttpClient(new IHttpRequestInterceptor[0], Mocker.Resolve<CacheManager>(), Mocker.Resolve<RateLimitService>(), Mocker.Resolve<IHttpDispatcher>(), Mocker.Resolve<UserAgentBuilder>(), TestLogger));
|
||||
Mocker.SetConstant<ILidarrCloudRequestBuilder>(new LidarrCloudRequestBuilder());
|
||||
Mocker.SetConstant<IMetadataRequestBuilder>(Mocker.Resolve<MetadataRequestBuilder>());
|
||||
|
|
Loading…
Reference in New Issue