Merge pull request #942 from Krivoblotsky/master

'304 Not Modified' HTTP status code handling.
This commit is contained in:
Bogdan Poplauschi 2014-11-02 23:52:10 +02:00
commit b596c9c120
1 changed files with 13 additions and 3 deletions

View File

@ -195,7 +195,9 @@
#pragma mark NSURLConnection (delegate)
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
if (![response respondsToSelector:@selector(statusCode)] || [((NSHTTPURLResponse *)response) statusCode] < 400) {
//'304 Not Modified' is an exceptional one
if ((![response respondsToSelector:@selector(statusCode)] || [((NSHTTPURLResponse *)response) statusCode] < 400) && [((NSHTTPURLResponse *)response) statusCode] != 304) {
NSInteger expected = response.expectedContentLength > 0 ? (NSInteger)response.expectedContentLength : 0;
self.expectedSize = expected;
if (self.progressBlock) {
@ -205,7 +207,15 @@
self.imageData = [[NSMutableData alloc] initWithCapacity:expected];
}
else {
[self.connection cancel];
NSUInteger code = [((NSHTTPURLResponse *)response) statusCode];
//This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
//In case of 304 we need just cancel the operation and return cached image from the cache.
if (code == 304) {
[self cancelInternal];
} else {
[self.connection cancel];
}
[[NSNotificationCenter defaultCenter] postNotificationName:SDWebImageDownloadStopNotification object:nil];