Ben Copsey

Add tests for expiry

... ... @@ -27,13 +27,15 @@ static NSDateFormatter *rfc1123DateFormatter = nil;
if (self == [ASIDownloadCache class]) {
rfc1123DateFormatter = [[NSDateFormatter alloc] init];
[rfc1123DateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[rfc1123DateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"];
[rfc1123DateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
[rfc1123DateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss 'GMT'"];
}
}
- (id)init
{
self = [super init];
[self setShouldRespectCacheControlHeaders:YES];
[self setDefaultCachePolicy:ASIReloadIfDifferentCachePolicy];
[self setDefaultCacheStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];
[self setAccessLock:[[[NSRecursiveLock alloc] init] autorelease]];
... ...
... ... @@ -23,7 +23,7 @@
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.6.2-15 2010-05-03";
NSString *ASIHTTPRequestVersion = @"v1.6.2-16 2010-05-04";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ...
... ... @@ -163,7 +163,28 @@
[request startSynchronous];
success = ![request didUseCachedResponse];
GHAssertTrue(success,@"Should not have used data cached in default cache");
}
- (void)testExpiry
{
[[ASIDownloadCache sharedCache] clearCachedResponsesForStoragePolicy:ASICacheForSessionDurationCacheStoragePolicy];
NSArray *headers = [NSArray arrayWithObjects:@"last-modified",@"etag",@"expires",@"max-age",nil];
for (NSString *header in headers) {
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://asi/ASIHTTPRequest/tests/content-always-new/%@",header]]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request startSynchronous];
if ([header isEqualToString:@"last-modified"]) {
[NSThread sleepForTimeInterval:2];
}
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://asi/ASIHTTPRequest/tests/content-always-new/%@",header]]];
[request setDownloadCache:[ASIDownloadCache sharedCache]];
[request startSynchronous];
BOOL success = ![request didUseCachedResponse];
GHAssertTrue(success,@"Cached data should have expired");
}
}
@end
... ...