Added the ability to set the default timeout
Tweak locking behaviour for session credentials
Showing
3 changed files
with
34 additions
and
2 deletions
| @@ -506,6 +506,11 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -506,6 +506,11 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
| 506 | // Called automatically when a request is started to clean up any persistent connections that have expired | 506 | // Called automatically when a request is started to clean up any persistent connections that have expired |
| 507 | + (void)expirePersistentConnections; | 507 | + (void)expirePersistentConnections; |
| 508 | 508 | ||
| 509 | +#pragma mark default time out | ||
| 510 | + | ||
| 511 | ++ (NSTimeInterval)defaultTimeOutSeconds; | ||
| 512 | ++ (void)setDefaultTimeOutSeconds:(NSTimeInterval)newTimeOutSeconds; | ||
| 513 | + | ||
| 509 | #pragma mark session credentials | 514 | #pragma mark session credentials |
| 510 | 515 | ||
| 511 | + (NSMutableArray *)sessionProxyCredentialsStore; | 516 | + (NSMutableArray *)sessionProxyCredentialsStore; |
| @@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
| 21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
| 22 | 22 | ||
| 23 | // Automatically set on build | 23 | // Automatically set on build |
| 24 | -NSString *ASIHTTPRequestVersion = @"v1.5-42 2010-02-03"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-43 2010-02-04"; |
| 25 | 25 | ||
| 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
| 27 | 27 | ||
| @@ -40,6 +40,9 @@ static NSMutableArray *sessionCookies = nil; | @@ -40,6 +40,9 @@ static NSMutableArray *sessionCookies = nil; | ||
| 40 | // The number of times we will allow requests to redirect before we fail with a redirection error | 40 | // The number of times we will allow requests to redirect before we fail with a redirection error |
| 41 | const int RedirectionLimit = 5; | 41 | const int RedirectionLimit = 5; |
| 42 | 42 | ||
| 43 | +// The default number of seconds to use for a timeout | ||
| 44 | +static NSTimeInterval defaultTimeOutSeconds = 10; | ||
| 45 | + | ||
| 43 | static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventType type, void *clientCallBackInfo) { | 46 | static void ReadStreamClientCallBack(CFReadStreamRef readStream, CFStreamEventType type, void *clientCallBackInfo) { |
| 44 | [((ASIHTTPRequest*)clientCallBackInfo) handleNetworkEvent: type]; | 47 | [((ASIHTTPRequest*)clientCallBackInfo) handleNetworkEvent: type]; |
| 45 | } | 48 | } |
| @@ -227,7 +230,7 @@ static BOOL isiPhoneOS2; | @@ -227,7 +230,7 @@ static BOOL isiPhoneOS2; | ||
| 227 | [self setDefaultResponseEncoding:NSISOLatin1StringEncoding]; | 230 | [self setDefaultResponseEncoding:NSISOLatin1StringEncoding]; |
| 228 | [self setShouldPresentProxyAuthenticationDialog:YES]; | 231 | [self setShouldPresentProxyAuthenticationDialog:YES]; |
| 229 | 232 | ||
| 230 | - [self setTimeOutSeconds:10]; | 233 | + [self setTimeOutSeconds:[ASIHTTPRequest defaultTimeOutSeconds]]; |
| 231 | [self setUseSessionPersistance:YES]; | 234 | [self setUseSessionPersistance:YES]; |
| 232 | [self setUseCookiePersistance:YES]; | 235 | [self setUseCookiePersistance:YES]; |
| 233 | [self setValidatesSecureCertificate:YES]; | 236 | [self setValidatesSecureCertificate:YES]; |
| @@ -2733,21 +2736,37 @@ static BOOL isiPhoneOS2; | @@ -2733,21 +2736,37 @@ static BOOL isiPhoneOS2; | ||
| 2733 | return newRequest; | 2736 | return newRequest; |
| 2734 | } | 2737 | } |
| 2735 | 2738 | ||
| 2739 | +#pragma mark default time out | ||
| 2740 | + | ||
| 2741 | ++ (NSTimeInterval)defaultTimeOutSeconds | ||
| 2742 | +{ | ||
| 2743 | + return defaultTimeOutSeconds; | ||
| 2744 | +} | ||
| 2745 | + | ||
| 2746 | ++ (void)setDefaultTimeOutSeconds:(NSTimeInterval)newTimeOutSeconds | ||
| 2747 | +{ | ||
| 2748 | + defaultTimeOutSeconds = newTimeOutSeconds; | ||
| 2749 | +} | ||
| 2750 | + | ||
| 2736 | #pragma mark session credentials | 2751 | #pragma mark session credentials |
| 2737 | 2752 | ||
| 2738 | + (NSMutableArray *)sessionProxyCredentialsStore | 2753 | + (NSMutableArray *)sessionProxyCredentialsStore |
| 2739 | { | 2754 | { |
| 2755 | + [sessionCredentialsLock lock]; | ||
| 2740 | if (!sessionProxyCredentialsStore) { | 2756 | if (!sessionProxyCredentialsStore) { |
| 2741 | sessionProxyCredentialsStore = [[NSMutableArray alloc] init]; | 2757 | sessionProxyCredentialsStore = [[NSMutableArray alloc] init]; |
| 2742 | } | 2758 | } |
| 2759 | + [sessionCredentialsLock unlock]; | ||
| 2743 | return sessionProxyCredentialsStore; | 2760 | return sessionProxyCredentialsStore; |
| 2744 | } | 2761 | } |
| 2745 | 2762 | ||
| 2746 | + (NSMutableArray *)sessionCredentialsStore | 2763 | + (NSMutableArray *)sessionCredentialsStore |
| 2747 | { | 2764 | { |
| 2765 | + [sessionCredentialsLock lock]; | ||
| 2748 | if (!sessionCredentialsStore) { | 2766 | if (!sessionCredentialsStore) { |
| 2749 | sessionCredentialsStore = [[NSMutableArray alloc] init]; | 2767 | sessionCredentialsStore = [[NSMutableArray alloc] init]; |
| 2750 | } | 2768 | } |
| 2769 | + [sessionCredentialsLock unlock]; | ||
| 2751 | return sessionCredentialsStore; | 2770 | return sessionCredentialsStore; |
| 2752 | } | 2771 | } |
| 2753 | 2772 |
| @@ -242,6 +242,14 @@ | @@ -242,6 +242,14 @@ | ||
| 242 | 242 | ||
| 243 | BOOL success = [[request error] code] == ASIRequestTimedOutErrorType; | 243 | BOOL success = [[request error] code] == ASIRequestTimedOutErrorType; |
| 244 | GHAssertTrue(success,@"Timeout didn't generate the correct error"); | 244 | GHAssertTrue(success,@"Timeout didn't generate the correct error"); |
| 245 | + | ||
| 246 | + [ASIHTTPRequest setDefaultTimeOutSeconds:0.0001]; | ||
| 247 | + [request startSynchronous]; | ||
| 248 | + | ||
| 249 | + success = [[request error] code] == ASIRequestTimedOutErrorType; | ||
| 250 | + GHAssertTrue(success,@"Failed to change the default timeout"); | ||
| 251 | + | ||
| 252 | + [ASIHTTPRequest setDefaultTimeOutSeconds:10]; | ||
| 245 | } | 253 | } |
| 246 | 254 | ||
| 247 | 255 |
-
Please register or login to post a comment