Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Open
tonyarnold opened this Issue · 1 comment

2 participants

@tonyarnold

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:

````AFCacheableItem *cacheableItem = [[AFCache sharedInstance] cachedObjectForURL:thumbnailFullSizeSrc delegate:nil];


Am I doing something wrong?
@dqueffeulouatw

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.