Merge branch 'url-redirect-block' of https://github.com/kcharwood/AFNetworking into kcharwood-url-redirect-block
This commit is contained in:
commit
d17b2998d7
2 changed files with 26 additions and 0 deletions
|
|
@ -241,4 +241,11 @@ extern NSString * const AFNetworkingOperationDidFinishNotification;
|
||||||
*/
|
*/
|
||||||
- (void)setCacheResponseBlock:(NSCachedURLResponse * (^)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse))block;
|
- (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
|
@end
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ typedef void (^AFURLConnectionOperationProgressBlock)(NSInteger bytes, long long
|
||||||
typedef BOOL (^AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace);
|
typedef BOOL (^AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace);
|
||||||
typedef void (^AFURLConnectionOperationAuthenticationChallengeBlock)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge);
|
typedef void (^AFURLConnectionOperationAuthenticationChallengeBlock)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge);
|
||||||
typedef NSCachedURLResponse * (^AFURLConnectionOperationCacheResponseBlock)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse);
|
typedef NSCachedURLResponse * (^AFURLConnectionOperationCacheResponseBlock)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse);
|
||||||
|
typedef NSURLRequest * (^AFURLConnectionOperationRedirectResponseBlock)(NSURLConnection *inConnection, NSURLRequest *inRequest, NSURLResponse*inRedirectResponse);
|
||||||
|
|
||||||
static inline NSString * AFKeyPathFromOperationState(AFOperationState state) {
|
static inline NSString * AFKeyPathFromOperationState(AFOperationState state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|
@ -116,6 +117,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
@property (readwrite, nonatomic, copy) AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock authenticationAgainstProtectionSpace;
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock authenticationAgainstProtectionSpace;
|
||||||
@property (readwrite, nonatomic, copy) AFURLConnectionOperationAuthenticationChallengeBlock authenticationChallenge;
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationAuthenticationChallengeBlock authenticationChallenge;
|
||||||
@property (readwrite, nonatomic, copy) AFURLConnectionOperationCacheResponseBlock cacheResponse;
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationCacheResponseBlock cacheResponse;
|
||||||
|
@property (readwrite, nonatomic, copy) AFURLConnectionOperationRedirectResponseBlock redirectResponse;
|
||||||
|
|
||||||
- (void)operationDidStart;
|
- (void)operationDidStart;
|
||||||
- (void)finish;
|
- (void)finish;
|
||||||
|
|
@ -140,6 +142,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
@synthesize authenticationAgainstProtectionSpace = _authenticationAgainstProtectionSpace;
|
@synthesize authenticationAgainstProtectionSpace = _authenticationAgainstProtectionSpace;
|
||||||
@synthesize authenticationChallenge = _authenticationChallenge;
|
@synthesize authenticationChallenge = _authenticationChallenge;
|
||||||
@synthesize cacheResponse = _cacheResponse;
|
@synthesize cacheResponse = _cacheResponse;
|
||||||
|
@synthesize redirectResponse = _redirectResponse;
|
||||||
@synthesize lock = _lock;
|
@synthesize lock = _lock;
|
||||||
|
|
||||||
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
|
+ (void)networkRequestThreadEntryPoint:(id)__unused object {
|
||||||
|
|
@ -212,6 +215,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[_authenticationChallenge release];
|
[_authenticationChallenge release];
|
||||||
[_authenticationAgainstProtectionSpace release];
|
[_authenticationAgainstProtectionSpace release];
|
||||||
[_cacheResponse release];
|
[_cacheResponse release];
|
||||||
|
[_redirectResponse release];
|
||||||
|
|
||||||
[_connection release];
|
[_connection release];
|
||||||
|
|
||||||
|
|
@ -305,6 +309,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
self.cacheResponse = block;
|
self.cacheResponse = block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setURLRedirectResponseBlock:(NSURLRequest *(^)(NSURLConnection *, NSURLRequest *, NSURLResponse *))block{
|
||||||
|
self.redirectResponse = block;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setState:(AFOperationState)state {
|
- (void)setState:(AFOperationState)state {
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
if (AFStateTransitionIsValid(self.state, state, [self isCancelled])) {
|
if (AFStateTransitionIsValid(self.state, state, [self isCancelled])) {
|
||||||
|
|
@ -579,4 +587,15 @@ 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
|
@end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue