Use nested if/else instead of early return in -connection:didReceiveAuthenticationChallenge:
This commit is contained in:
parent
8869bb9ad3
commit
bdab46889b
1 changed files with 20 additions and 21 deletions
|
|
@ -318,28 +318,27 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
{
|
{
|
||||||
if (self.authenticationBlock) {
|
if (self.authenticationBlock) {
|
||||||
self.authenticationBlock(connection, challenge);
|
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 {
|
} 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];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue