Skip to content

Commit

Permalink
Merge branch 'nolanw-request-delegate-gets-failed-auth-challenge'
Browse files Browse the repository at this point in the history
  • Loading branch information
blakewatters committed Dec 14, 2011
2 parents a1e2061 + e5e05a0 commit d6510d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Code/Network/RKRequest.h
Expand Up @@ -469,4 +469,9 @@ typedef enum {
*/ */
- (void)requestDidTimeout:(RKRequest *)request; - (void)requestDidTimeout:(RKRequest *)request;


/**
* Sent when a request fails authentication
*/
- (void)request:(RKRequest *)request didFailAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;

@end @end
15 changes: 9 additions & 6 deletions Code/Network/RKResponse.m
Expand Up @@ -51,9 +51,7 @@ - (id)init {
- (id)initWithRequest:(RKRequest*)request { - (id)initWithRequest:(RKRequest*)request {
self = [self init]; self = [self init];
if (self) { if (self) {
// We don't retain here as we're letting RKRequestQueue manage _request = [request retain];
// request ownership
_request = request;
} }


return self; return self;
Expand All @@ -73,7 +71,7 @@ - (id)initWithRequest:(RKRequest*)request body:(NSData*)body headers:(NSDictiona
- (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLResponse*)URLResponse body:(NSData*)body error:(NSError*)error { - (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLResponse*)URLResponse body:(NSData*)body error:(NSError*)error {
self = [super init]; self = [super init];
if (self) { if (self) {
_request = request; _request = [request retain];
_httpURLResponse = [URLResponse retain]; _httpURLResponse = [URLResponse retain];
_failureError = [error retain]; _failureError = [error retain];
_body = [[NSMutableData dataWithData:body] retain]; _body = [[NSMutableData dataWithData:body] retain];
Expand All @@ -84,6 +82,8 @@ - (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLRespo
} }


- (void)dealloc { - (void)dealloc {
[_request release];
_request = nil;
[_httpURLResponse release]; [_httpURLResponse release];
_httpURLResponse = nil; _httpURLResponse = nil;
[_body release]; [_body release];
Expand Down Expand Up @@ -151,8 +151,11 @@ - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallen
[[challenge sender] useCredential:newCredential [[challenge sender] useCredential:newCredential
forAuthenticationChallenge:challenge]; forAuthenticationChallenge:challenge];
} else { } else {
RKLogWarning(@"Failed authentication challenge after %ld failures", (long) [challenge previousFailureCount]); RKLogWarning(@"Failed authentication challenge after %ld failures", (long) [challenge previousFailureCount]);
[[challenge sender] cancelAuthenticationChallenge:challenge]; if ([[_request delegate] respondsToSelector:@selector(request:didFailAuthenticationChallenge:)]) {
[[_request delegate] request:_request didFailAuthenticationChallenge:challenge];
}
[[challenge sender] cancelAuthenticationChallenge:challenge];
} }
} }


Expand Down

0 comments on commit d6510d9

Please sign in to comment.