Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add handling for image returned with 404 http response (fixes #399) #396

Merged
merged 6 commits into from Aug 24, 2017

Conversation

wsdwsd0829
Copy link
Contributor

There are cases when image is returned along with 404 HttpResponse, this pr will handle the edge case from within framework.
Since we manage cache any way, may be not necessary to expose api to client to handle this case?
Side Notes: NSUrlSession can handle this case correctly in NSURLSessionDataDelegate.

@wsdwsd0829
Copy link
Contributor Author

@garrettmoon let me know if you have any ideas around it, Thanks.

@ghost
Copy link

ghost commented Aug 22, 2017

🚫 CI failed with log

@wsdwsd0829
Copy link
Contributor Author

CI failing because of flakiness of testResume & testResumeSkipCancelation

@wsdwsd0829
Copy link
Contributor Author

@appleguy @garrettmoon new fixes based on the fact that url session works for 404 image out of box.

@appleguy
Copy link
Contributor

@garrettmoon - it looks like testResume might be a flaky test; should it be disabled?

PINRemoteImage_Tests
testResume, ((resume.resumeData.length > 0) is true) failed - Resume should have > 0 data length
/Users/Shared/buildkite/builds/iosf-garrett-VMrmmvuqKsO4.dyn.pinadmin.com-1/pinterest/pinremoteimage/Tests/PINRemoteImageTests.m:1169

  PINResume *resume = [self.imageManager.cache objectFromDiskForKey:[self.imageManager resumeCacheKeyForURL:[self progressiveURL]]];
  XCTAssert(resume.resumeData.length > 0, @"Resume should have > 0 data length");

testResume, failed: caught "NSInternalInconsistencyException", "PINResume must have all fields non-nil and non-zero length."
/Users/Shared/buildkite/builds/iosf-garrett-VMrmmvuqKsO4.dyn.pinadmin.com-1/pinterest/pinremoteimage/Tests/PINRemoteImageTests.m:1172

  //Shorten resume data to improve reliability of test (expect to get progressive render callback before download completes.
  resume = [PINResume resumeData:[resume.resumeData subdataWithRange:NSMakeRange(0, 10)] ifRange:resume.ifRange totalBytes:resume.totalBytes];
  [self.imageManager.cache setObjectOnDisk:resume forKey:[self.imageManager resumeCacheKeyForURL:[self progressiveURL]]];

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

@wsdwsd0829 wsdwsd0829 changed the title add handling for image returned with 404 http response add handling for image returned with 404 http response (fixes #399) Aug 23, 2017
@wsdwsd0829
Copy link
Contributor Author

This fixes #399, similar issues reported here SDWebImage/SDWebImage#530

@garrettmoon
Copy link
Collaborator

@appleguy sadly it's totally flakey, but I'm not willing to disable at this point. I am however happy to rerun the tests as many times as necessary :)

I've actually spent a bit of time attempting to make the tests less flakey, but I think the only solution is to write a web server for the tests and I'm reluctant to invest in that right now :(

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

Copy link
Collaborator

@garrettmoon garrettmoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the result include an error if there's a 404 as well as an image? Otherwise how can the client of PINRemoteImage know a 404 was returned?

Separately, is it common practice to return an image with a 404 response? Any documentation on something like this?

XCTAssertNotNil(result.image);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the same timeout as used in the other tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -188,6 +188,14 @@ - (NSURL *)progressiveURL
return bigURLs;
}

- (NSURL *)imageFrom404URL
{
NSString *base64EncodedUrl = @"aHR0cHM6Ly9pLnl0aW1nLmNvbS92aS9PRzlRbW9jNGVZcy9tcWRlZmF1bHQuanBn";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cough

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

@wsdwsd0829
Copy link
Contributor Author

wsdwsd0829 commented Aug 23, 2017

If we return the error, the PINRemoteImageManager will not handler data correctly (the error will short cut the data to image handling, can be see my previous attempt to fix here 539137c). Also I thought this is a very special case and responseRecoverableFrom404 can handle it well enough.
If it's just normal 404 there would not be data and "image/jpeg" in response header;

@wsdwsd0829
Copy link
Contributor Author

examples refer to here: SDWebImage/SDWebImage#530
curl https://i4.ytimg.com -i

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

if (statusCode >= 400) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
NSInteger statusCode = [response statusCode];
BOOL recoverable = [self responseRecoverableFrom404:response];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a comment that says something along the lines of:
"If a 404 response contains an image, we treat it as a successful request and return the image"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added & thanks for approval.

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented Aug 23, 2017

🚫 CI failed with log

Copy link
Collaborator

@maicki maicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@garrettmoon
Copy link
Collaborator

YAY! CI Passed!

@wsdwsd0829 do you mind adding an entry to the CHANGELOG.md?

@wsdwsd0829
Copy link
Contributor Author

Added to change log

@garrettmoon garrettmoon merged commit 8098372 into pinterest:master Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants