Showing
6 changed files
with
21 additions
and
4 deletions
| @@ -14,6 +14,7 @@ static ASIDownloadCache *sharedCache = nil; | @@ -14,6 +14,7 @@ static ASIDownloadCache *sharedCache = nil; | ||
| 14 | 14 | ||
| 15 | static NSString *sessionCacheFolder = @"SessionStore"; | 15 | static NSString *sessionCacheFolder = @"SessionStore"; |
| 16 | static NSString *permanentCacheFolder = @"PermanentStore"; | 16 | static NSString *permanentCacheFolder = @"PermanentStore"; |
| 17 | +static NSDateFormatter *rfc1123DateFormatter = nil; | ||
| 17 | 18 | ||
| 18 | @interface ASIDownloadCache () | 19 | @interface ASIDownloadCache () |
| 19 | + (NSString *)keyForRequest:(ASIHTTPRequest *)request; | 20 | + (NSString *)keyForRequest:(ASIHTTPRequest *)request; |
| @@ -21,6 +22,15 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -21,6 +22,15 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 21 | 22 | ||
| 22 | @implementation ASIDownloadCache | 23 | @implementation ASIDownloadCache |
| 23 | 24 | ||
| 25 | ++ (void)initialize | ||
| 26 | +{ | ||
| 27 | + if (self == [ASIDownloadCache class]) { | ||
| 28 | + rfc1123DateFormatter = [[NSDateFormatter alloc] init]; | ||
| 29 | + [rfc1123DateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; | ||
| 30 | + [rfc1123DateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"]; | ||
| 31 | + } | ||
| 32 | +} | ||
| 33 | + | ||
| 24 | - (id)init | 34 | - (id)init |
| 25 | { | 35 | { |
| 26 | self = [super init]; | 36 | self = [super init]; |
| @@ -109,13 +119,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -109,13 +119,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 109 | [responseHeaders removeObjectForKey:@"Content-Encoding"]; | 119 | [responseHeaders removeObjectForKey:@"Content-Encoding"]; |
| 110 | } | 120 | } |
| 111 | // We use this special key to help expire the request when we get a max-age header | 121 | // We use this special key to help expire the request when we get a max-age header |
| 112 | - [responseHeaders setObject:[NSDate date] forKey:@"X-ASIHTTPRequest-Fetch-date"]; | 122 | + [responseHeaders setObject:[rfc1123DateFormatter stringFromDate:[NSDate date]] forKey:@"X-ASIHTTPRequest-Fetch-date"]; |
| 113 | [responseHeaders writeToFile:metadataPath atomically:NO]; | 123 | [responseHeaders writeToFile:metadataPath atomically:NO]; |
| 114 | 124 | ||
| 115 | if ([request responseData]) { | 125 | if ([request responseData]) { |
| 116 | [[request responseData] writeToFile:dataPath atomically:NO]; | 126 | [[request responseData] writeToFile:dataPath atomically:NO]; |
| 117 | } else if ([request downloadDestinationPath]) { | 127 | } else if ([request downloadDestinationPath]) { |
| 118 | - [[NSFileManager defaultManager] copyPath:[request downloadDestinationPath] toPath:dataPath handler:nil]; | 128 | + NSError *error = nil; |
| 129 | + [[NSFileManager defaultManager] copyItemAtPath:[request downloadDestinationPath] toPath:dataPath error:&error]; | ||
| 119 | } | 130 | } |
| 120 | [[self accessLock] unlock]; | 131 | [[self accessLock] unlock]; |
| 121 | 132 | ||
| @@ -208,8 +219,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | @@ -208,8 +219,14 @@ static NSString *permanentCacheFolder = @"PermanentStore"; | ||
| 208 | [scanner scanString:@"=" intoString:NULL]; | 219 | [scanner scanString:@"=" intoString:NULL]; |
| 209 | NSTimeInterval maxAge = 0; | 220 | NSTimeInterval maxAge = 0; |
| 210 | [scanner scanDouble:&maxAge]; | 221 | [scanner scanDouble:&maxAge]; |
| 211 | - NSDate *fetchDate = [[cachedHeaders objectForKey:@"X-ASIHTTPRequest-Fetch-date"] dateValue]; | 222 | + NSDate *fetchDate = [ASIHTTPRequest dateFromRFC1123String:[cachedHeaders objectForKey:@"X-ASIHTTPRequest-Fetch-date"]]; |
| 223 | + | ||
| 224 | +#if (TARGET_OS_IPHONE && (!defined(__IPHONE_4_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_4_0)) || !defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 | ||
| 212 | NSDate *expiryDate = [fetchDate addTimeInterval:maxAge]; | 225 | NSDate *expiryDate = [fetchDate addTimeInterval:maxAge]; |
| 226 | +#else | ||
| 227 | + NSDate *expiryDate = [fetchDate dateByAddingTimeInterval:maxAge]; | ||
| 228 | +#endif | ||
| 229 | + | ||
| 213 | if ([expiryDate timeIntervalSinceNow] < 0) { | 230 | if ([expiryDate timeIntervalSinceNow] < 0) { |
| 214 | return NO; | 231 | return NO; |
| 215 | } | 232 | } |
| @@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | // Automatically set on build | 25 | // Automatically set on build |
| 26 | -NSString *ASIHTTPRequestVersion = @"v1.6.2-14 2010-05-03"; | 26 | +NSString *ASIHTTPRequestVersion = @"v1.6.2-15 2010-05-03"; |
| 27 | 27 | ||
| 28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 28 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 29 | 29 |
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
-
Please register or login to post a comment