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
add handling for image returned with 404 http response (fixes #399) #396
Conversation
@garrettmoon let me know if you have any ideas around it, Thanks. |
🚫 CI failed with log |
CI failing because of flakiness of testResume & testResumeSkipCancelation |
@appleguy @garrettmoon new fixes based on the fact that url session works for 404 image out of box. |
@garrettmoon - it looks like testResume might be a flaky test; should it be disabled?
|
🚫 CI failed with log |
This fixes #399, similar issues reported here SDWebImage/SDWebImage#530 |
@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 :( |
🚫 CI failed with log |
There was a problem hiding this 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?
Tests/PINRemoteImageTests.m
Outdated
XCTAssertNotNil(result.image); | ||
[expectation fulfill]; | ||
}]; | ||
[self waitForExpectationsWithTimeout:5 handler:^(NSError * _Nullable error) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cough
🚫 CI failed with log |
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. |
examples refer to here: SDWebImage/SDWebImage#530 |
🚫 CI failed with log |
if (statusCode >= 400) { | ||
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; | ||
NSInteger statusCode = [response statusCode]; | ||
BOOL recoverable = [self responseRecoverableFrom404:response]; |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added & thanks for approval.
🚫 CI failed with log |
🚫 CI failed with log |
🚫 CI failed with log |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
YAY! CI Passed! @wsdwsd0829 do you mind adding an entry to the CHANGELOG.md? |
Added to change log |
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.