diff --git a/External/ASI/ASICacheDelegate.h b/External/ASI/ASICacheDelegate.h index 060cda5..5ce260b 100644 --- a/External/ASI/ASICacheDelegate.h +++ b/External/ASI/ASICacheDelegate.h @@ -100,4 +100,6 @@ typedef enum _ASICacheStoragePolicy { // Clear cached data stored for the passed storage policy - (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy; +- (NSURL*) cacheUrl:(ASIHTTPRequest*) request; + @end diff --git a/External/ASI/ASIDownloadCache.m b/External/ASI/ASIDownloadCache.m index b0c9990..a873a43 100644 --- a/External/ASI/ASIDownloadCache.m +++ b/External/ASI/ASIDownloadCache.m @@ -262,7 +262,8 @@ - (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request if (![extension length]) { extension = @"html"; } - path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[request url]] stringByAppendingPathExtension:extension]]; + path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[self cacheUrl:request]] stringByAppendingPathExtension:extension]]; + [[self accessLock] unlock]; return path; } @@ -275,7 +276,8 @@ - (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)reque return nil; } NSString *path = [[self storagePath] stringByAppendingPathComponent:([request cacheStoragePolicy] == ASICacheForSessionDurationCacheStoragePolicy ? sessionCacheFolder : permanentCacheFolder)]; - path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[request url]] stringByAppendingPathExtension:@"cachedheaders"]]; + path = [path stringByAppendingPathComponent:[[[self class] keyForURL:[self cacheUrl:request]] stringByAppendingPathExtension:@"cachedheaders"]]; + [[self accessLock] unlock]; return path; } @@ -303,7 +305,7 @@ - (void)removeCachedDataForURL:(NSURL *)url - (void)removeCachedDataForRequest:(ASIHTTPRequest *)request { - [self removeCachedDataForURL:[request url]]; + [self removeCachedDataForURL:[self cacheUrl:request]]; } - (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request @@ -313,12 +315,12 @@ - (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request [[self accessLock] unlock]; return NO; } - NSDictionary *cachedHeaders = [self cachedResponseHeadersForURL:[request url]]; + NSDictionary *cachedHeaders = [self cachedResponseHeadersForURL:[self cacheUrl:request]]; if (!cachedHeaders) { [[self accessLock] unlock]; return NO; } - NSString *dataPath = [self pathToCachedResponseDataForURL:[request url]]; + NSString *dataPath = [self pathToCachedResponseDataForURL:[self cacheUrl:request]]; if (!dataPath) { [[self accessLock] unlock]; return NO; @@ -461,11 +463,11 @@ - (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request return YES; } - NSDictionary *headers = [self cachedResponseHeadersForURL:[request url]]; + NSDictionary *headers = [self cachedResponseHeadersForURL:[self cacheUrl:request]]; if (!headers) { return NO; } - NSString *dataPath = [self pathToCachedResponseDataForURL:[request url]]; + NSString *dataPath = [self pathToCachedResponseDataForURL:[self cacheUrl:request]]; if (!dataPath) { return NO; } @@ -497,6 +499,19 @@ - (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request return NO; } +- (NSURL*) cacheUrl:(ASIHTTPRequest*) request +{ + NSURL * url = [request url]; + if(![request.requestMethod isEqualToString:@"GET"] && [request.postBody length]>0) + { + NSString * postString = [ASIHTTPRequest base64forData:request.postBody]; + + url = [NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",[request url].absoluteString,postString]]; + } + + return url; +} + @synthesize storagePath; @synthesize defaultCachePolicy; @synthesize accessLock; diff --git a/External/ASI/ASIHTTPRequest.m b/External/ASI/ASIHTTPRequest.m index a5c0a36..d86835c 100644 --- a/External/ASI/ASIHTTPRequest.m +++ b/External/ASI/ASIHTTPRequest.m @@ -892,11 +892,11 @@ - (void)main if (![self mainRequest]) { [self buildPostBody]; } - + /* if (![[self requestMethod] isEqualToString:@"GET"]) { [self setDownloadCache:nil]; } - + */ // If we're redirecting, we'll already have a CFHTTPMessageRef if (request) { @@ -3577,8 +3577,8 @@ - (void)markAsFinished - (void)useDataFromCache { - NSDictionary *headers = [[self downloadCache] cachedResponseHeadersForURL:[self url]]; - NSString *dataPath = [[self downloadCache] pathToCachedResponseDataForURL:[self url]]; + NSDictionary *headers = [[self downloadCache] cachedResponseHeadersForURL:[[self downloadCache] cacheUrl:self]]; + NSString *dataPath = [[self downloadCache] pathToCachedResponseDataForURL:[[self downloadCache] cacheUrl:self]]; ASIHTTPRequest *theRequest = self; if ([self mainRequest]) { @@ -3594,7 +3594,7 @@ - (void)useDataFromCache if ([theRequest downloadDestinationPath]) { [theRequest setDownloadDestinationPath:dataPath]; } else { - [theRequest setRawResponseData:[NSMutableData dataWithData:[[self downloadCache] cachedResponseDataForURL:[self url]]]]; + [theRequest setRawResponseData:[NSMutableData dataWithData:[[self downloadCache] cachedResponseDataForURL:[[self downloadCache] cacheUrl:self]]]]; } [theRequest setContentLength:[[[self responseHeaders] objectForKey:@"Content-Length"] longLongValue]]; [theRequest setTotalBytesRead:[self contentLength]];