...
|
...
|
@@ -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,8 +207,16 @@ |
|
|
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];
|
|
|
|
|
|
if (self.completedBlock) {
|
...
|
...
|
|