Browse files

Fix for ocassional crashes using http basic auth

  • Loading branch information...
1 parent 6a18ebd commit 7be7da61cb8cfceef05572097dce4c7787d1528e @rayfix rayfix committed with blakewatters Jan 8, 2012
Showing with 9 additions and 6 deletions.
  1. +9 −6 Code/Network/RKRequest.m
View
15 Code/Network/RKRequest.m
@@ -234,12 +234,15 @@ - (void)addHeadersToRequest {
// Add authentication headers so we don't have to deal with an extra cycle for each message requiring basic auth.
if (self.authenticationType == RKRequestAuthenticationTypeHTTPBasic && _username && _password) {
CFHTTPMessageRef dummyRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)[self HTTPMethod], (CFURLRef)[self URL], kCFHTTPVersion1_1);
-
- CFHTTPMessageAddAuthentication(dummyRequest, nil, (CFStringRef)_username, (CFStringRef)_password,kCFHTTPAuthenticationSchemeBasic, FALSE);
- CFStringRef authorizationString = CFHTTPMessageCopyHeaderFieldValue(dummyRequest, CFSTR("Authorization"));
- [_URLRequest setValue:(NSString *)authorizationString forHTTPHeaderField:@"Authorization"];
- CFRelease(dummyRequest);
- CFRelease(authorizationString);
+ if (dummyRequest) {
+ CFHTTPMessageAddAuthentication(dummyRequest, nil, (CFStringRef)_username, (CFStringRef)_password,kCFHTTPAuthenticationSchemeBasic, FALSE);
+ CFStringRef authorizationString = CFHTTPMessageCopyHeaderFieldValue(dummyRequest, CFSTR("Authorization"));
+ if (authorizationString) {
+ [_URLRequest setValue:(NSString *)authorizationString forHTTPHeaderField:@"Authorization"];
+ CFRelease(authorizationString);
+ }
+ CFRelease(dummyRequest);
+ }
}
// Add OAuth headers if is need it

0 comments on commit 7be7da6

Please sign in to comment.