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 {
195
195
#pragma mark NSURLConnection (delegate)
196
196
197
197
- (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 ) {
199
201
NSInteger expected = response.expectedContentLength > 0 ? (NSInteger )response.expectedContentLength : 0 ;
200
202
self.expectedSize = expected;
201
203
if (self.progressBlock ) {
@@ -205,8 +207,16 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
205
207
self.imageData = [[NSMutableData alloc ] initWithCapacity: expected];
206
208
}
207
209
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
+
210
220
[[NSNotificationCenter defaultCenter ] postNotificationName: SDWebImageDownloadStopNotification object: nil ];
211
221
212
222
if (self.completedBlock ) {
You can’t perform that action at this time.
0 commit comments