Fixed header request.

This commit is contained in:
kay.one 2013-06-02 23:12:31 -07:00
parent 233def11c7
commit a997c10ca1
4 changed files with 16 additions and 8 deletions

View File

@ -6,12 +6,12 @@ using NzbDrone.Test.Common;
namespace NzbDrone.Common.Test namespace NzbDrone.Common.Test
{ {
[TestFixture] [TestFixture]
public class WebClientTests : TestBase public class WebClientTests : TestBase<HttpProvider>
{ {
[Test] [Test]
public void DownloadString_should_be_able_to_dowload_text_file() 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().NotBeBlank();
jquery.Should().Contain("Sitemap"); jquery.Should().Contain("Sitemap");
@ -23,7 +23,15 @@ namespace NzbDrone.Common.Test
[ExpectedException] [ExpectedException]
public void DownloadString_should_throw_on_error(string url) 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();
} }
} }
} }

View File

@ -13,7 +13,7 @@ namespace NzbDrone.Common
string DownloadString(string address); string DownloadString(string address);
string DownloadString(string address, string username, string password); string DownloadString(string address, string username, string password);
string DownloadString(string address, ICredentials identity); string DownloadString(string address, ICredentials identity);
Dictionary<string, string> DownloadHeader(string url); Dictionary<string, string> GetHeader(string url);
Stream DownloadStream(string url, NetworkCredential credential = null); Stream DownloadStream(string url, NetworkCredential credential = null);
void DownloadFile(string url, string fileName); void DownloadFile(string url, string fileName);
@ -60,7 +60,7 @@ namespace NzbDrone.Common
} }
} }
public Dictionary<string, string> DownloadHeader(string url) public Dictionary<string, string> GetHeader(string url)
{ {
var headers = new Dictionary<string, string>(); var headers = new Dictionary<string, string>();
var request = WebRequest.Create(url); var request = WebRequest.Create(url);
@ -68,7 +68,7 @@ namespace NzbDrone.Common
var response = request.GetResponse(); var response = request.GetResponse();
foreach (var key in headers.Keys) foreach (var key in response.Headers.AllKeys)
{ {
headers.Add(key, response.Headers[key]); headers.Add(key, response.Headers[key]);
} }

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Core.Test.MediaCoverTests
{ {
_headers = new Dictionary<string, string>(); _headers = new Dictionary<string, string>();
Mocker.GetMock<IDiskProvider>().Setup(c => c.GetFileSize(It.IsAny<string>())).Returns(100); Mocker.GetMock<IDiskProvider>().Setup(c => c.GetFileSize(It.IsAny<string>())).Returns(100);
Mocker.GetMock<IHttpProvider>().Setup(c => c.DownloadHeader(It.IsAny<string>())).Returns(_headers); Mocker.GetMock<IHttpProvider>().Setup(c => c.GetHeader(It.IsAny<string>())).Returns(_headers);
} }

View File

@ -29,7 +29,7 @@ namespace NzbDrone.Core.MediaCover
return false; return false;
} }
var headers = _httpProvider.DownloadHeader(url); var headers = _httpProvider.GetHeader(url);
string sizeString; string sizeString;