From aa5c3783ea870eef287570707c82a1d807152504 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 25 May 2012 15:03:19 -0700 Subject: [PATCH] Minor refactoring, code formatting, and documentation changes --- AFNetworking/AFURLConnectionOperation.h | 15 +++++++------- AFNetworking/AFURLConnectionOperation.m | 26 ++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 52711ec..0da353a 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -234,6 +234,14 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; */ - (void)setAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))block; +/** + Sets a block to be executed when the server redirects the request from one URL to another URL, or when the request URL changed by the `NSURLProtocol` subclass handling the request in order to standardize its format, as handled by the `NSURLConnectionDelegate` method `connection:willSendRequest:redirectResponse:`. + + @param block A block object to be executed when the request URL was changed. The block returns an `NSURLRequest` object, the URL request to redirect, and takes three arguments: the URL connection object, the the proposed redirected request, and the URL response that caused the redirect. + */ +- (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block; + + /** Sets a block to be executed to modify the response a connection will cache, if any, as handled by the `NSURLConnectionDelegate` method `connection:willCacheResponse:`. @@ -241,11 +249,4 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; */ - (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block; -/** - Sets a block to be executed to modify the URL request when a redirct is encountered as handled by the `NSURLConnectionDelegate` method `connection:willSendRequest:redirectResponse:`. - - @param block A block object to be executed to determine the properties of a redirected URL request. The block returns an `NSURLRequest` object, the URL request to redirect, and takes three arguments: the URL connection object, the new URL request, the URL redirect response. - */ -- (void)setURLRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *inConnection, NSURLRequest *inRequest, NSURLResponse*inRedirectResponse))block; - @end diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index b13f8b2..9686580 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -54,7 +54,7 @@ typedef void (^AFURLConnectionOperationProgressBlock)(NSInteger bytes, long long typedef BOOL (^AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace); typedef void (^AFURLConnectionOperationAuthenticationChallengeBlock)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge); typedef NSCachedURLResponse * (^AFURLConnectionOperationCacheResponseBlock)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse); -typedef NSURLRequest * (^AFURLConnectionOperationRedirectResponseBlock)(NSURLConnection *inConnection, NSURLRequest *inRequest, NSURLResponse*inRedirectResponse); +typedef NSURLRequest * (^AFURLConnectionOperationRedirectResponseBlock)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse); static inline NSString * AFKeyPathFromOperationState(AFOperationState state) { switch (state) { @@ -309,7 +309,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat self.cacheResponse = block; } -- (void)setURLRedirectResponseBlock:(NSURLRequest *(^)(NSURLConnection *, NSURLRequest *, NSURLResponse *))block{ +- (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))block { self.redirectResponse = block; } @@ -518,6 +518,17 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge } } +- (NSURLRequest *)connection:(NSURLConnection *)connection + willSendRequest:(NSURLRequest *)request + redirectResponse:(NSURLResponse *)redirectResponse; +{ + if (self.redirectResponse) { + return self.redirectResponse(connection, request, redirectResponse); + } else { + return request; + } +} + - (void)connection:(NSURLConnection *)__unused connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten @@ -587,15 +598,4 @@ didReceiveResponse:(NSURLResponse *)response } } -- (NSURLRequest *)connection:(NSURLConnection *)inConnection - willSendRequest:(NSURLRequest *)inRequest - redirectResponse:(NSURLResponse *)inRedirectResponse; -{ - if(self.redirectResponse) - return self.redirectResponse(inConnection, inRequest, inRedirectResponse); - else { - return inRequest; - } -} - @end