mirror of
https://github.com/fergalmoran/Readarr.git
synced 2025-12-29 21:07:35 +00:00
Fixed: Corrupt image files when downloading from redirecting Url
(cherry picked from commit e28b2e83284f689d3620d8d394ef35fdfd55646f) Closes #108
This commit is contained in:
@@ -322,6 +322,31 @@ namespace NzbDrone.Common.Test.Http
|
||||
ExceptionVerification.ExpectedWarns(1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_write_redirect_content_to_stream()
|
||||
{
|
||||
var file = GetTempFilePath();
|
||||
|
||||
using (var fileStream = new FileStream(file, FileMode.Create))
|
||||
{
|
||||
var request = new HttpRequest($"http://{_httpBinHost}/redirect/1");
|
||||
request.AllowAutoRedirect = false;
|
||||
request.ResponseStream = fileStream;
|
||||
|
||||
var response = Subject.Get(request);
|
||||
|
||||
response.StatusCode.Should().Be(HttpStatusCode.Redirect);
|
||||
}
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
|
||||
File.Exists(file).Should().BeTrue();
|
||||
|
||||
var fileInfo = new FileInfo(file);
|
||||
|
||||
fileInfo.Length.Should().Be(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_send_cookie()
|
||||
{
|
||||
|
||||
@@ -127,9 +127,10 @@ namespace NzbDrone.Common.Http.Dispatchers
|
||||
{
|
||||
try
|
||||
{
|
||||
if (request.ResponseStream != null)
|
||||
if (request.ResponseStream != null && httpWebResponse.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
// A target ResponseStream was specified, write to that instead.
|
||||
// But only on the OK status code, since we don't want to write failures and redirects.
|
||||
responseStream.CopyTo(request.ResponseStream);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user