Showing
2 changed files
with
38 additions
and
37 deletions
@@ -276,7 +276,7 @@ | @@ -276,7 +276,7 @@ | ||
276 | NSError *err = nil; | 276 | NSError *err = nil; |
277 | unsigned long long fileSize = [[[[NSFileManager defaultManager] attributesOfItemAtPath:file error:&err] objectForKey:NSFileSize] unsignedLongLongValue]; | 277 | unsigned long long fileSize = [[[[NSFileManager defaultManager] attributesOfItemAtPath:file error:&err] objectForKey:NSFileSize] unsignedLongLongValue]; |
278 | if (err) { | 278 | if (err) { |
279 | - [self addToDebugBody:[NSString stringWithFormat:@"[Error: Failed to obtain the file of the file at '%@']",file]]; | 279 | + [self addToDebugBody:[NSString stringWithFormat:@"[Error: Failed to obtain the size of the file at '%@']",file]]; |
280 | } else { | 280 | } else { |
281 | [self addToDebugBody:[NSString stringWithFormat:@"[%llu bytes of data from file '%@']",fileSize,file]]; | 281 | [self addToDebugBody:[NSString stringWithFormat:@"[%llu bytes of data from file '%@']",fileSize,file]]; |
282 | } | 282 | } |
@@ -612,51 +612,52 @@ static BOOL isiPhoneOS2; | @@ -612,51 +612,52 @@ static BOOL isiPhoneOS2; | ||
612 | - (void)applyAuthorizationHeader | 612 | - (void)applyAuthorizationHeader |
613 | { | 613 | { |
614 | // Do we want to send credentials before we are asked for them? | 614 | // Do we want to send credentials before we are asked for them? |
615 | - if ([self shouldPresentCredentialsBeforeChallenge]) { | 615 | + if (![self shouldPresentCredentialsBeforeChallenge]) { |
616 | - | 616 | + return; |
617 | - // First, see if we have any credentials we can use in the session store | 617 | + } |
618 | - NSDictionary *credentials = nil; | ||
619 | - if ([self useSessionPersistance]) { | ||
620 | - credentials = [self findSessionAuthenticationCredentials]; | ||
621 | - } | ||
622 | 618 | ||
619 | + // First, see if we have any credentials we can use in the session store | ||
620 | + NSDictionary *credentials = nil; | ||
621 | + if ([self useSessionPersistance]) { | ||
622 | + credentials = [self findSessionAuthenticationCredentials]; | ||
623 | + } | ||
624 | + | ||
625 | + | ||
626 | + // Are any credentials set on this request that might be used for basic authentication? | ||
627 | + if ([self username] && [self password] && ![self domain]) { | ||
623 | 628 | ||
624 | - // Are any credentials set on this request that might be used for basic authentication? | 629 | + // If we have stored credentials, is this server asking for basic authentication? If we don't have credentials, we'll assume basic |
625 | - if ([self username] && [self password] && ![self domain]) { | 630 | + if (!credentials || (CFStringRef)[credentials objectForKey:@"AuthenticationScheme"] == kCFHTTPAuthenticationSchemeBasic) { |
626 | - | 631 | + [self addBasicAuthenticationHeaderWithUsername:[self username] andPassword:[self password]]; |
627 | - // If we have stored credentials, is this server asking for basic authentication? If we don't have credentials, we'll assume basic | ||
628 | - if (!credentials || (CFStringRef)[credentials objectForKey:@"AuthenticationScheme"] == kCFHTTPAuthenticationSchemeBasic) { | ||
629 | - [self addBasicAuthenticationHeaderWithUsername:[self username] andPassword:[self password]]; | ||
630 | - } | ||
631 | } | 632 | } |
633 | + } | ||
634 | + | ||
635 | + if (credentials && ![[self requestHeaders] objectForKey:@"Authorization"]) { | ||
632 | 636 | ||
633 | - if (credentials && ![[self requestHeaders] objectForKey:@"Authorization"]) { | 637 | + // When the Authentication key is set, the credentials were stored after an authentication challenge, so we can let CFNetwork apply them |
638 | + // (credentials for Digest and NTLM will always be stored like this) | ||
639 | + if ([credentials objectForKey:@"Authentication"]) { | ||
634 | 640 | ||
635 | - // When the Authentication key is set, the credentials were stored after an authentication challenge, so we can let CFNetwork apply them | 641 | + // If we've already talked to this server and have valid credentials, let's apply them to the request |
636 | - // (credentials for Digest and NTLM will always be stored like this) | 642 | + if (!CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { |
637 | - if ([credentials objectForKey:@"Authentication"]) { | 643 | + [[self class] removeAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; |
638 | - | ||
639 | - // If we've already talked to this server and have valid credentials, let's apply them to the request | ||
640 | - if (!CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { | ||
641 | - [[self class] removeAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; | ||
642 | - } | ||
643 | - | ||
644 | - // If the Authentication key is not set, these credentials were stored after a username and password set on a previous request passed basic authentication | ||
645 | - // When this happens, we'll need to create the Authorization header ourselves | ||
646 | - } else { | ||
647 | - NSDictionary *usernameAndPassword = [credentials objectForKey:@"Credentials"]; | ||
648 | - [self addBasicAuthenticationHeaderWithUsername:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationUsername] andPassword:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationPassword]]; | ||
649 | } | 644 | } |
645 | + | ||
646 | + // If the Authentication key is not set, these credentials were stored after a username and password set on a previous request passed basic authentication | ||
647 | + // When this happens, we'll need to create the Authorization header ourselves | ||
648 | + } else { | ||
649 | + NSDictionary *usernameAndPassword = [credentials objectForKey:@"Credentials"]; | ||
650 | + [self addBasicAuthenticationHeaderWithUsername:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationUsername] andPassword:[usernameAndPassword objectForKey:(NSString *)kCFHTTPAuthenticationPassword]]; | ||
650 | } | 651 | } |
651 | - if ([self useSessionPersistance]) { | 652 | + } |
652 | - credentials = [self findSessionProxyAuthenticationCredentials]; | 653 | + if ([self useSessionPersistance]) { |
653 | - if (credentials) { | 654 | + credentials = [self findSessionProxyAuthenticationCredentials]; |
654 | - if (!CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { | 655 | + if (credentials) { |
655 | - [[self class] removeProxyAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; | 656 | + if (!CFHTTPMessageApplyCredentialDictionary(request, (CFHTTPAuthenticationRef)[credentials objectForKey:@"Authentication"], (CFDictionaryRef)[credentials objectForKey:@"Credentials"], NULL)) { |
656 | - } | 657 | + [[self class] removeProxyAuthenticationCredentialsFromSessionStore:[credentials objectForKey:@"Credentials"]]; |
657 | } | 658 | } |
658 | } | 659 | } |
659 | - } | 660 | + } |
660 | } | 661 | } |
661 | 662 | ||
662 | - (void)buildRequestHeaders | 663 | - (void)buildRequestHeaders |
-
Please register or login to post a comment