Added delegate callback when authentication challenge fails. closes #462

This commit is contained in:
Blake Watters
2011-12-13 21:16:30 -05:00
2 changed files with 14 additions and 6 deletions

View File

@@ -469,4 +469,9 @@ typedef enum {
*/
- (void)requestDidTimeout:(RKRequest *)request;
/**
* Sent when a request fails authentication
*/
- (void)request:(RKRequest *)request didFailAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
@end

View File

@@ -51,9 +51,7 @@ extern NSString* cacheURLKey;
- (id)initWithRequest:(RKRequest*)request {
self = [self init];
if (self) {
// We don't retain here as we're letting RKRequestQueue manage
// request ownership
_request = request;
_request = [request retain];
}
return self;
@@ -73,7 +71,7 @@ extern NSString* cacheURLKey;
- (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLResponse*)URLResponse body:(NSData*)body error:(NSError*)error {
self = [super init];
if (self) {
_request = request;
_request = [request retain];
_httpURLResponse = [URLResponse retain];
_failureError = [error retain];
_body = [[NSMutableData dataWithData:body] retain];
@@ -84,6 +82,8 @@ extern NSString* cacheURLKey;
}
- (void)dealloc {
[_request release];
_request = nil;
[_httpURLResponse release];
_httpURLResponse = nil;
[_body release];
@@ -151,8 +151,11 @@ extern NSString* cacheURLKey;
[[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge];
} else {
RKLogWarning(@"Failed authentication challenge after %ld failures", (long) [challenge previousFailureCount]);
[[challenge sender] cancelAuthenticationChallenge:challenge];
RKLogWarning(@"Failed authentication challenge after %ld failures", (long) [challenge previousFailureCount]);
if ([[_request delegate] respondsToSelector:@selector(request:didFailAuthenticationChallenge:)]) {
[[_request delegate] request:_request didFailAuthenticationChallenge:challenge];
}
[[challenge sender] cancelAuthenticationChallenge:challenge];
}
}