File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -195,7 +195,9 @@ - (BOOL)isConcurrent {
195195#pragma mark NSURLConnection (delegate)
196196
197197- (void )connection : (NSURLConnection *)connection didReceiveResponse : (NSURLResponse *)response {
198- if (![response respondsToSelector: @selector (statusCode )] || [((NSHTTPURLResponse *)response) statusCode ] < 400 ) {
198+
199+ // '304 Not Modified' is an exceptional one
200+ if ((![response respondsToSelector: @selector (statusCode )] || [((NSHTTPURLResponse *)response) statusCode ] < 400 ) && [((NSHTTPURLResponse *)response) statusCode ] != 304 ) {
199201 NSInteger expected = response.expectedContentLength > 0 ? (NSInteger )response.expectedContentLength : 0 ;
200202 self.expectedSize = expected;
201203 if (self.progressBlock ) {
@@ -205,8 +207,16 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
205207 self.imageData = [[NSMutableData alloc ] initWithCapacity: expected];
206208 }
207209 else {
208- [self .connection cancel ];
209-
210+ NSUInteger code = [((NSHTTPURLResponse *)response) statusCode ];
211+
212+ // This is the case when server returns '304 Not Modified'. It means that remote image is not changed.
213+ // In case of 304 we need just cancel the operation and return cached image from the cache.
214+ if (code == 304 ) {
215+ [self cancelInternal ];
216+ } else {
217+ [self .connection cancel ];
218+ }
219+
210220 [[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
211221
212222 if (self.completedBlock ) {
You can’t perform that action at this time.
0 commit comments