Use nested if/else instead of early return in -connection:didReceiveAuthenticationChallenge:

This commit is contained in:
Mattt Thompson 2012-01-10 13:41:36 -08:00
parent 8869bb9ad3
commit bdab46889b

View file

@ -318,28 +318,27 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
if (self.authenticationBlock) {
self.authenticationBlock(connection, challenge);
return;
}
if ([challenge previousFailureCount] == 0) {
NSURLCredential *credential = nil;
NSString *username = [(NSString *)CFURLCopyUserName((CFURLRef)[self.request URL]) autorelease];
NSString *password = [(NSString *)CFURLCopyPassword((CFURLRef)[self.request URL]) autorelease];
if (username && password) {
credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
} else if (username) {
credential = [[[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[challenge protectionSpace]] objectForKey:username];
} else {
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
}
if (credential) {
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
} else {
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
if ([challenge previousFailureCount] == 0) {
NSURLCredential *credential = nil;
NSString *username = [(NSString *)CFURLCopyUserName((CFURLRef)[self.request URL]) autorelease];
NSString *password = [(NSString *)CFURLCopyPassword((CFURLRef)[self.request URL]) autorelease];
if (username && password) {
credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
} else if (username) {
credential = [[[NSURLCredentialStorage sharedCredentialStorage] credentialsForProtectionSpace:[challenge protectionSpace]] objectForKey:username];
} else {
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
}
if (credential) {
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
} else {
[[challenge sender] continueWithoutCredentialForAuthenticationChallenge:challenge];
}
}
}