Jamie Pinkham

added hooks for request redirects

... ... @@ -469,6 +469,9 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
//block for handling proxy authentication
ASIHTTPRequestBlock proxyAuthenticationNeededBlock;
//block for handling redirections, if you want to
ASIHTTPRequestBlock requestRedirectedBlock;
#endif
}
... ... @@ -495,6 +498,7 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
- (void)setDataReceivedBlock:(ASIHTTPRequestDataReceivedBlock)aReceivedBlock;
- (void)setAuthenticationNeededBlock:(ASIHTTPRequestBlock)anAuthenticationBlock;
- (void)setProxyAuthenticationNeededBlock:(ASIHTTPRequestBlock)aProxyAuthenticationBlock;
- (void)setRequestRedirectedBlock:(ASIHTTPRequestBlock)aRedirectBlock;
#endif
#pragma mark setup request
... ...
... ... @@ -430,6 +430,11 @@ static NSOperationQueue *sharedQueue = nil;
[proxyAuthenticationNeededBlock release];
proxyAuthenticationNeededBlock = [aProxyAuthenticationBlock copy];
}
- (void)setRequestRedirectedBlock:(ASIHTTPRequestBlock)aRedirectBlock{
[requestRedirectedBlock release];
requestRedirectedBlock = [aRedirectBlock copy];
}
#endif
#pragma mark setup request
... ... @@ -1996,6 +2001,16 @@ static NSOperationQueue *sharedQueue = nil;
if ([self shouldRedirect] && [responseHeaders valueForKey:@"Location"]) {
if (([self responseStatusCode] > 300 && [self responseStatusCode] < 304) || [self responseStatusCode] == 307) {
if([[self delegate] respondsToSelector:@selector(requestRedirected:)]){
[[self delegate] performSelectorOnMainThread:@selector(requestRedirected:) withObject:self waitUntilDone:[NSThread isMainThread]];
}
#if NS_BLOCKS_AVAILABLE
if(requestRedirectedBlock){
__block ASIHTTPRequest *blockCopy = self;
requestRedirectedBlock(blockCopy);
}
#endif
// By default, we redirect 301 and 302 response codes as GET requests
// According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen
// See also:
... ...
... ... @@ -18,6 +18,7 @@
- (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
- (void)requestRedirected:(ASIHTTPRequest *)request;
// When a delegate implements this method, it is expected to process all incoming data itself
// This means that responseData / responseString / downloadDestinationPath etc are ignored
... ...