From 5385af5f12367bea6fce7a67220066921123c86c Mon Sep 17 00:00:00 2001 From: Ben Copsey Date: Sat, 28 May 2011 11:21:33 +0100 Subject: [PATCH] Prevent synchronous requests from using delegate authentication or ASIAuthenticationDialog Comment tweaks --- Classes/ASIHTTPRequest.h | 3 ++- Classes/ASIHTTPRequest.m | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Classes/ASIHTTPRequest.h b/Classes/ASIHTTPRequest.h index c3b46f16..6212f013 100644 --- a/Classes/ASIHTTPRequest.h +++ b/Classes/ASIHTTPRequest.h @@ -229,6 +229,7 @@ typedef void (^ASIDataBlock)(NSData *data); int authenticationRetryCount; // Authentication scheme (Basic, Digest, NTLM) + // If you are using Basic authentication and want to force ASIHTTPRequest to send an authorization header without waiting for a 401, you must set this to (NSString *)kCFHTTPAuthenticationSchemeBasic NSString *authenticationScheme; // Realm for authentication when credentials are required @@ -294,7 +295,7 @@ typedef void (^ASIDataBlock)(NSData *data); SEL didReceiveResponseHeadersSelector; // Called on the delegate (if implemented) when the request receives a Location header and shouldRedirect is YES - // The delegate can then change the url if needed, and can restart the request by calling [request resume], or simply cancel it + // The delegate can then change the url if needed, and can restart the request by calling [request redirectToURL:], or simply cancel it SEL willRedirectSelector; // Called on the delegate (if implemented) when the request completes successfully. Default is requestFinished: diff --git a/Classes/ASIHTTPRequest.m b/Classes/ASIHTTPRequest.m index 15c5e921..5ef5741e 100644 --- a/Classes/ASIHTTPRequest.m +++ b/Classes/ASIHTTPRequest.m @@ -2611,21 +2611,29 @@ - (void)failAuthentication - (BOOL)showProxyAuthenticationDialog { -// Mac authentication dialog coming soon! -#if TARGET_OS_IPHONE + if ([self isSynchronous]) { + return NO; + } + + // Mac authentication dialog coming soon! + #if TARGET_OS_IPHONE if ([self shouldPresentProxyAuthenticationDialog]) { [ASIAuthenticationDialog performSelectorOnMainThread:@selector(presentAuthenticationDialogForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]]; return YES; } return NO; -#else + #else return NO; -#endif + #endif } - (BOOL)willAskDelegateForProxyCredentials { + if ([self isSynchronous]) { + return NO; + } + // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:. // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate id authenticationDelegate = [self delegate]; @@ -2673,6 +2681,10 @@ - (void)askDelegateForProxyCredentials - (BOOL)willAskDelegateForCredentials { + if ([self isSynchronous]) { + return NO; + } + // If we have a delegate, we'll see if it can handle proxyAuthenticationNeededForRequest:. // Otherwise, we'll try the queue (if this request is part of one) and it will pass the message on to its own delegate id authenticationDelegate = [self delegate]; @@ -2875,16 +2887,19 @@ - (void)attemptToApplyProxyCredentialsAndResume - (BOOL)showAuthenticationDialog { -// Mac authentication dialog coming soon! -#if TARGET_OS_IPHONE + if ([self isSynchronous]) { + return NO; + } + // Mac authentication dialog coming soon! + #if TARGET_OS_IPHONE if ([self shouldPresentAuthenticationDialog]) { [ASIAuthenticationDialog performSelectorOnMainThread:@selector(presentAuthenticationDialogForRequest:) withObject:self waitUntilDone:[NSThread isMainThread]]; return YES; } return NO; -#else + #else return NO; -#endif + #endif } - (void)attemptToApplyCredentialsAndResume