Jamie Pinkham

added hooks for request redirects

@@ -468,7 +468,10 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData @@ -468,7 +468,10 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
468 ASIHTTPRequestBlock authenticationNeededBlock; 468 ASIHTTPRequestBlock authenticationNeededBlock;
469 469
470 //block for handling proxy authentication 470 //block for handling proxy authentication
471 - ASIHTTPRequestBlock proxyAuthenticationNeededBlock; 471 + ASIHTTPRequestBlock proxyAuthenticationNeededBlock;
  472 +
  473 + //block for handling redirections, if you want to
  474 + ASIHTTPRequestBlock requestRedirectedBlock;
472 #endif 475 #endif
473 } 476 }
474 477
@@ -495,6 +498,7 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData @@ -495,6 +498,7 @@ typedef void (^ASIHTTPRequestDataReceivedBlock)(ASIHTTPRequest *request, NSData
495 - (void)setDataReceivedBlock:(ASIHTTPRequestDataReceivedBlock)aReceivedBlock; 498 - (void)setDataReceivedBlock:(ASIHTTPRequestDataReceivedBlock)aReceivedBlock;
496 - (void)setAuthenticationNeededBlock:(ASIHTTPRequestBlock)anAuthenticationBlock; 499 - (void)setAuthenticationNeededBlock:(ASIHTTPRequestBlock)anAuthenticationBlock;
497 - (void)setProxyAuthenticationNeededBlock:(ASIHTTPRequestBlock)aProxyAuthenticationBlock; 500 - (void)setProxyAuthenticationNeededBlock:(ASIHTTPRequestBlock)aProxyAuthenticationBlock;
  501 +- (void)setRequestRedirectedBlock:(ASIHTTPRequestBlock)aRedirectBlock;
498 #endif 502 #endif
499 503
500 #pragma mark setup request 504 #pragma mark setup request
@@ -430,6 +430,11 @@ static NSOperationQueue *sharedQueue = nil; @@ -430,6 +430,11 @@ static NSOperationQueue *sharedQueue = nil;
430 [proxyAuthenticationNeededBlock release]; 430 [proxyAuthenticationNeededBlock release];
431 proxyAuthenticationNeededBlock = [aProxyAuthenticationBlock copy]; 431 proxyAuthenticationNeededBlock = [aProxyAuthenticationBlock copy];
432 } 432 }
  433 +
  434 +- (void)setRequestRedirectedBlock:(ASIHTTPRequestBlock)aRedirectBlock{
  435 + [requestRedirectedBlock release];
  436 + requestRedirectedBlock = [aRedirectBlock copy];
  437 +}
433 #endif 438 #endif
434 439
435 #pragma mark setup request 440 #pragma mark setup request
@@ -1995,6 +2000,16 @@ static NSOperationQueue *sharedQueue = nil; @@ -1995,6 +2000,16 @@ static NSOperationQueue *sharedQueue = nil;
1995 // Note that ASIHTTPRequest does not currently support 305 Use Proxy 2000 // Note that ASIHTTPRequest does not currently support 305 Use Proxy
1996 if ([self shouldRedirect] && [responseHeaders valueForKey:@"Location"]) { 2001 if ([self shouldRedirect] && [responseHeaders valueForKey:@"Location"]) {
1997 if (([self responseStatusCode] > 300 && [self responseStatusCode] < 304) || [self responseStatusCode] == 307) { 2002 if (([self responseStatusCode] > 300 && [self responseStatusCode] < 304) || [self responseStatusCode] == 307) {
  2003 +
  2004 + if([[self delegate] respondsToSelector:@selector(requestRedirected:)]){
  2005 + [[self delegate] performSelectorOnMainThread:@selector(requestRedirected:) withObject:self waitUntilDone:[NSThread isMainThread]];
  2006 + }
  2007 +#if NS_BLOCKS_AVAILABLE
  2008 + if(requestRedirectedBlock){
  2009 + __block ASIHTTPRequest *blockCopy = self;
  2010 + requestRedirectedBlock(blockCopy);
  2011 + }
  2012 +#endif
1998 2013
1999 // By default, we redirect 301 and 302 response codes as GET requests 2014 // By default, we redirect 301 and 302 response codes as GET requests
2000 // According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen 2015 // According to RFC 2616 this is wrong, but this is what most browsers do, so it's probably what you're expecting to happen
@@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
18 - (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request; 18 - (void)requestReceivedResponseHeaders:(ASIHTTPRequest *)request;
19 - (void)requestFinished:(ASIHTTPRequest *)request; 19 - (void)requestFinished:(ASIHTTPRequest *)request;
20 - (void)requestFailed:(ASIHTTPRequest *)request; 20 - (void)requestFailed:(ASIHTTPRequest *)request;
  21 +- (void)requestRedirected:(ASIHTTPRequest *)request;
21 22
22 // When a delegate implements this method, it is expected to process all incoming data itself 23 // When a delegate implements this method, it is expected to process all incoming data itself
23 // This means that responseData / responseString / downloadDestinationPath etc are ignored 24 // This means that responseData / responseString / downloadDestinationPath etc are ignored