Ben Copsey

Fix removing cached headers (Thanks to Taggart Gorman for catching this!)

@@ -49,6 +49,7 @@ typedef enum _ASICacheStoragePolicy { @@ -49,6 +49,7 @@ typedef enum _ASICacheStoragePolicy {
49 49
50 // Same as the above, but returns a path to the cached response body instead 50 // Same as the above, but returns a path to the cached response body instead
51 - (NSString *)pathToCachedResponseDataForRequest:(ASIHTTPRequest *)request; 51 - (NSString *)pathToCachedResponseDataForRequest:(ASIHTTPRequest *)request;
  52 +- (NSString *)pathToCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
52 53
53 // Clear cached data stored for the passed storage policy 54 // Clear cached data stored for the passed storage policy
54 - (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy; 55 - (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy;
@@ -195,6 +195,32 @@ static NSString *permanentCacheFolder = @"PermanentStore"; @@ -195,6 +195,32 @@ static NSString *permanentCacheFolder = @"PermanentStore";
195 return nil; 195 return nil;
196 } 196 }
197 197
  198 +- (NSString *)pathToCachedResponseHeadersForRequest:(ASIHTTPRequest *)request
  199 +{
  200 + [[self accessLock] lock];
  201 + if (![self storagePath]) {
  202 + [[self accessLock] unlock];
  203 + return nil;
  204 + }
  205 + // Look in the session store
  206 + NSString *path = [[self storagePath] stringByAppendingPathComponent:sessionCacheFolder];
  207 + NSString *dataPath = [path stringByAppendingPathComponent:[[[self class] keyForRequest:request] stringByAppendingPathExtension:@"cachedheaders"]];
  208 + if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
  209 + [[self accessLock] unlock];
  210 + return dataPath;
  211 + }
  212 + // Look in the permanent store
  213 + path = [[self storagePath] stringByAppendingPathComponent:permanentCacheFolder];
  214 + dataPath = [path stringByAppendingPathComponent:[[[self class] keyForRequest:request] stringByAppendingPathExtension:@"cachedheaders"]];
  215 + if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
  216 + [[self accessLock] unlock];
  217 + return dataPath;
  218 + }
  219 + [[self accessLock] unlock];
  220 + return nil;
  221 +}
  222 +
  223 +
198 - (void)removeCachedDataForRequest:(ASIHTTPRequest *)request 224 - (void)removeCachedDataForRequest:(ASIHTTPRequest *)request
199 { 225 {
200 [[self accessLock] lock]; 226 [[self accessLock] lock];
@@ -202,7 +228,7 @@ static NSString *permanentCacheFolder = @"PermanentStore"; @@ -202,7 +228,7 @@ static NSString *permanentCacheFolder = @"PermanentStore";
202 [[self accessLock] unlock]; 228 [[self accessLock] unlock];
203 return; 229 return;
204 } 230 }
205 - NSString *cachedHeadersPath = [[self storagePath] stringByAppendingPathComponent:[[[self class] keyForRequest:request] stringByAppendingPathExtension:@"cachedheaders"]]; 231 + NSString *cachedHeadersPath = [self pathToCachedResponseHeadersForRequest:request];
206 if (!cachedHeadersPath) { 232 if (!cachedHeadersPath) {
207 [[self accessLock] unlock]; 233 [[self accessLock] unlock];
208 return; 234 return;