Permalink
Browse files

Merge branch 'nolanw-request-delegate-gets-failed-auth-challenge'

  • Loading branch information...
2 parents a1e2061 + e5e05a0 commit d6510d963f459135d7d15f66f29cb7aec486ea7f @blakewatters blakewatters committed Dec 14, 2011
Showing with 14 additions and 6 deletions.
  1. +5 −0 Code/Network/RKRequest.h
  2. +9 −6 Code/Network/RKResponse.m
View
@@ -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
@@ -51,9 +51,7 @@ - (id)init {
- (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 @@ - (id)initWithRequest:(RKRequest*)request body:(NSData*)body headers:(NSDictiona
- (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 @@ - (id)initWithSynchronousRequest:(RKRequest*)request URLResponse:(NSHTTPURLRespo
}
- (void)dealloc {
+ [_request release];
+ _request = nil;
[_httpURLResponse release];
_httpURLResponse = nil;
[_body release];
@@ -151,8 +151,11 @@ - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallen
[[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];
}
}

0 comments on commit d6510d9

Please sign in to comment.