diff --git a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs index a66a687c6..1d53b9051 100644 --- a/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs +++ b/src/NzbDrone.Core.Test/IndexerTests/SeasonSearchFixture.cs @@ -24,7 +24,9 @@ public void Setup() { _series = Builder.CreateNew().Build(); - Mocker.GetMock().Setup(s => s.DownloadString(It.IsAny())).Returns(""); + var response = new HttpResponse(null, new HttpHeader(), "", System.Net.HttpStatusCode.OK); + Mocker.GetMock() + .Setup(s => s.Get(It.IsAny())).Returns(response); } private IndexerBase WithIndexer(bool paging, int resultCount) @@ -57,7 +59,7 @@ public void should_not_use_offset_if_result_count_is_less_than_90() var indexer = WithIndexer(true, 25); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List{_series.Title} }); - Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Once()); } [Test] @@ -66,7 +68,7 @@ public void should_not_use_offset_for_sites_that_do_not_support_it() var indexer = WithIndexer(false, 125); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List { _series.Title } }); - Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Once()); + Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Once()); } [Test] @@ -75,7 +77,7 @@ public void should_not_use_offset_if_its_already_tried_10_times() var indexer = WithIndexer(true, 100); Subject.Fetch(indexer, new SeasonSearchCriteria { Series = _series, SceneTitles = new List { _series.Title } }); - Mocker.GetMock().Verify(v => v.DownloadString(It.IsAny()), Times.Exactly(10)); + Mocker.GetMock().Verify(v => v.Get(It.IsAny()), Times.Exactly(10)); } } diff --git a/src/NzbDrone.Core/Indexers/IndexerFetchService.cs b/src/NzbDrone.Core/Indexers/IndexerFetchService.cs index 253ee8386..2fd7bb9ae 100644 --- a/src/NzbDrone.Core/Indexers/IndexerFetchService.cs +++ b/src/NzbDrone.Core/Indexers/IndexerFetchService.cs @@ -24,11 +24,11 @@ public interface IFetchFeedFromIndexers public class FetchFeedService : IFetchFeedFromIndexers { private readonly Logger _logger; - private readonly IHttpProvider _httpProvider; + private readonly IHttpClient _httpClient; - public FetchFeedService(IHttpProvider httpProvider, Logger logger) + public FetchFeedService(IHttpClient httpClient, Logger logger) { - _httpProvider = httpProvider; + _httpClient = httpClient; _logger = logger; } @@ -140,7 +140,16 @@ private List Fetch(IIndexer indexer, IEnumerable urls) try { _logger.Debug("Downloading Feed " + url); - var xml = _httpProvider.DownloadString(url); + var request = new HttpRequest(url); + request.Headers.Accept = "text/xml, text/rss+xml, application/rss+xml"; + var response = _httpClient.Get(request); + + if (response.Headers.ContentType != null && response.Headers.ContentType.Split(';')[0] == "text/html") + { + throw new WebException("Indexer responded with html content. Site is likely blocked or unavailable."); + } + + var xml = response.Content; if (!string.IsNullOrWhiteSpace(xml)) { result.AddRange(indexer.Parser.Process(xml, url));