Browse Source

Minor refactoring, code formatting, and documentation changes

Mattt Thompson 13 years ago
parent
commit
aa5c3783ea
2 changed files with 20 additions and 19 deletions
  1. 7 6
      AFNetworking/AFURLConnectionOperation.h
  2. 13 13
      AFNetworking/AFURLConnectionOperation.m

+ 7 - 6
AFNetworking/AFURLConnectionOperation.h

@@ -235,17 +235,18 @@ extern NSString * const AFNetworkingOperationDidFinishNotification;
 - (void)setAuthenticationChallengeBlock:(void (^)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge))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:`.
+ 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 to determine what response a connection will cache, if any. The block returns an `NSCachedURLResponse` object, the cached response to store in memory or `nil` to prevent the response from being cached, and takes two arguments: the URL connection object, and the cached response provided for the request.
+ @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)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block;
+- (void)setRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *connection, NSURLRequest *request, NSURLResponse *redirectResponse))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:`.
+ Sets a block to be executed to modify the response a connection will cache, if any, as handled by the `NSURLConnectionDelegate` method `connection:willCacheResponse:`.
  
- @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.
+ @param block A block object to be executed to determine what response a connection will cache, if any. The block returns an `NSCachedURLResponse` object, the cached response to store in memory or `nil` to prevent the response from being cached, and takes two arguments: the URL connection object, and the cached response provided for the request.
  */
-- (void)setURLRedirectResponseBlock:(NSURLRequest * (^)(NSURLConnection *inConnection, NSURLRequest *inRequest, NSURLResponse*inRedirectResponse))block;
+- (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block;
 
 @end

+ 13 - 13
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