AFCache icon indicating copy to clipboard operation
AFCache copied to clipboard

AFCacheableItemInfo returning MIME type of 'plain/text' after first use

Open tonyarnold opened this issue 13 years ago • 1 comments

I've got an odd problem where I'm getting a MIME type of 'plain/text' on items that were previously 'image/jpeg' or 'video/mp4'. It seems to happen only after I've quit and restarted my app, or after I've recalled the item from cache already. Here's how I'm retrieving items from cache:


```

Am I doing something wrong?
```

tonyarnold avatar Apr 30 '11 08:04 tonyarnold

I have a similar problem. I've made a modification in AFURLCache that seems to fix the problem : I have to split the content-type and the charset :

-(NSCachedURLResponse_)cachedResponseForRequest:(NSURLRequest_)request { NSURL* url = request.URL; AFCacheableItem* item = [[AFCache sharedInstance] cacheableItemFromCacheStore:url]; if (item && item.cacheStatus == kCacheStatusFresh && item.data) { NSRange oRange = [item.info.mimeType rangeOfString:@"charset="]; NSString* oMimeType = item.info.mimeType; NSString* oCharset = nil; if (oRange.location != NSNotFound) { oMimeType = [[[item.info.mimeType substringToIndex:oRange.location] stringByReplacingOccurrencesOfString:@";" withString:@""] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; oCharset = [[item.info.mimeType substringFromIndex:(oRange.location + oRange.length)] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; } NSURLResponse* response = [[NSURLResponse alloc] initWithURL:item.url MIMEType:oMimeType expectedContentLength:[item.data length] textEncodingName:oCharset]; NSCachedURLResponse *cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:item.data userInfo:nil storagePolicy:NSURLCacheStorageAllowedInMemoryOnly]; [response release]; NSLog(@"Cache HIT for file: %@", [[AFCache sharedInstance] filenameForURL: url]); return [cachedResponse autorelease]; } else { NSLog(@"Cache miss for file: %@", [[AFCache sharedInstance] filenameForURL: url]); }

NSCachedURLResponse *response = [super cachedResponseForRequest:request];
return response;

}

Also I added a test on item.data because sometimes I got nil which ends with a blank page in UIWebView.

dqueffeulouatw avatar Jul 06 '11 14:07 dqueffeulouatw