From a997c10ca147db0b0b49e96eda439d2d82057ff1 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 2 Jun 2013 23:12:31 -0700 Subject: [PATCH] Fixed header request. --- NzbDrone.Common.Test/WebClientTests.cs | 14 +++++++++++--- NzbDrone.Common/HttpProvider.cs | 6 +++--- .../CoverExistsSpecificationFixture.cs | 2 +- .../MediaCover/CoverAlreadyExistsSpecification.cs | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/NzbDrone.Common.Test/WebClientTests.cs b/NzbDrone.Common.Test/WebClientTests.cs index 9c621cde4..6b7cbc356 100644 --- a/NzbDrone.Common.Test/WebClientTests.cs +++ b/NzbDrone.Common.Test/WebClientTests.cs @@ -6,12 +6,12 @@ using NzbDrone.Test.Common; namespace NzbDrone.Common.Test { [TestFixture] - public class WebClientTests : TestBase + public class WebClientTests : TestBase { [Test] public void DownloadString_should_be_able_to_dowload_text_file() { - var jquery = new HttpProvider(new EnvironmentProvider()).DownloadString("http://www.google.com/robots.txt"); + var jquery = Subject.DownloadString("http://www.google.com/robots.txt"); jquery.Should().NotBeBlank(); jquery.Should().Contain("Sitemap"); @@ -23,7 +23,15 @@ namespace NzbDrone.Common.Test [ExpectedException] public void DownloadString_should_throw_on_error(string url) { - var jquery = new HttpProvider(new EnvironmentProvider()).DownloadString(url); + var jquery = Subject.DownloadString(url); + } + + + [Test] + public void should_get_headers() + { + Subject.GetHeader("http://www.google.com").Should().NotBeEmpty(); } } + } diff --git a/NzbDrone.Common/HttpProvider.cs b/NzbDrone.Common/HttpProvider.cs index 0897ca079..d3b9f67ac 100644 --- a/NzbDrone.Common/HttpProvider.cs +++ b/NzbDrone.Common/HttpProvider.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Common string DownloadString(string address); string DownloadString(string address, string username, string password); string DownloadString(string address, ICredentials identity); - Dictionary DownloadHeader(string url); + Dictionary GetHeader(string url); Stream DownloadStream(string url, NetworkCredential credential = null); void DownloadFile(string url, string fileName); @@ -60,7 +60,7 @@ namespace NzbDrone.Common } } - public Dictionary DownloadHeader(string url) + public Dictionary GetHeader(string url) { var headers = new Dictionary(); var request = WebRequest.Create(url); @@ -68,7 +68,7 @@ namespace NzbDrone.Common var response = request.GetResponse(); - foreach (var key in headers.Keys) + foreach (var key in response.Headers.AllKeys) { headers.Add(key, response.Headers[key]); } diff --git a/NzbDrone.Core.Test/MediaCoverTests/CoverExistsSpecificationFixture.cs b/NzbDrone.Core.Test/MediaCoverTests/CoverExistsSpecificationFixture.cs index faffdacf0..0c87594df 100644 --- a/NzbDrone.Core.Test/MediaCoverTests/CoverExistsSpecificationFixture.cs +++ b/NzbDrone.Core.Test/MediaCoverTests/CoverExistsSpecificationFixture.cs @@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests { _headers = new Dictionary(); Mocker.GetMock().Setup(c => c.GetFileSize(It.IsAny())).Returns(100); - Mocker.GetMock().Setup(c => c.DownloadHeader(It.IsAny())).Returns(_headers); + Mocker.GetMock().Setup(c => c.GetHeader(It.IsAny())).Returns(_headers); } diff --git a/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs b/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs index 87d8151a1..fd4bcff52 100644 --- a/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs +++ b/NzbDrone.Core/MediaCover/CoverAlreadyExistsSpecification.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.MediaCover return false; } - var headers = _httpProvider.DownloadHeader(url); + var headers = _httpProvider.GetHeader(url); string sizeString;