<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -436,7 +436,6 @@ static BOOL isiPhoneOS2;
 // Create the request
 - (void)main
 {
-	
 	[pool release];
 	pool = [[NSAutoreleasePool alloc] init];
 	[self setComplete:NO];
@@ -455,7 +454,7 @@ static BOOL isiPhoneOS2;
 	if (request) {
 		CFRelease(request);
 	}
-	
+
     // Create a new HTTP request.
 	request = CFHTTPMessageCreateRequest(kCFAllocatorDefault, (CFStringRef)[self requestMethod], (CFURLRef)[self url], [self useHTTPVersionOne] ? kCFHTTPVersion1_0 : kCFHTTPVersion1_1);
     if (!request) {
@@ -666,6 +665,7 @@ static BOOL isiPhoneOS2;
 			readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, request);
 		}
 	}
+
 	if (!readStream) {
 		[[self cancelledLock] unlock];
 		[self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@&quot;Unable to create read stream&quot;,NSLocalizedDescriptionKey,nil]]];
@@ -813,16 +813,15 @@ static BOOL isiPhoneOS2;
 			// This workaround prevents erroneous timeouts in low bandwidth situations (eg iPhone)
 			if (totalBytesSent || postLength &lt;= uploadBufferSize || (uploadBufferSize &gt; 0 &amp;&amp; totalBytesSent &gt; uploadBufferSize)) {
 				[self failWithError:ASIRequestTimedOutError];
-				[[self cancelledLock] unlock];
 				[self cancelLoad];
 				[self setComplete:YES];
+				[[self cancelledLock] unlock];
 				break;
 			}
 		}
 		
 		// Do we need to redirect?
 		if ([self needsRedirect]) {
-			[[self cancelledLock] unlock];
 			[self cancelLoad];
 			[self setNeedsRedirect:NO];
 			[self setRedirectCount:[self redirectCount]+1];
@@ -830,8 +829,11 @@ static BOOL isiPhoneOS2;
 				// Some naughty / badly coded website is trying to force us into a redirection loop. This is not cool.
 				[self failWithError:ASITooMuchRedirectionError];
 				[self setComplete:YES];
+				[[self cancelledLock] unlock];
 			} else {
+				[[self cancelledLock] unlock];
 				// Go all the way back to the beginning and build the request again, so that we can apply any new cookies
+				
 				[self main];
 			}
 			break;
@@ -2801,7 +2803,7 @@ static BOOL isiPhoneOS2;
 		return nil;
 	}
 	// Obtain the list of proxies by running the autoconfiguration script
-#if TARGET_OS_IPHONE &amp;&amp; __IPHONE_OS_VERSION_MIN_REQUIRED &lt; __IPHONE_3_0
+#if TARGET_IPHONE_SIMULATOR &amp;&amp; __IPHONE_OS_VERSION_MIN_REQUIRED &lt; __IPHONE_3_0
 	NSArray *proxies = [(NSArray *)CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef)script,(CFURLRef)theURL) autorelease];
 #else
 	CFErrorRef err2 = NULL;</diff>
      <filename>Classes/ASIHTTPRequest.m</filename>
    </modified>
    <modified>
      <diff>@@ -17,6 +17,7 @@
 }
 
 - (void)testBasicDownload;
+- (void)testConditionalGET;
 - (void)testTimeOut;
 - (void)testRequestMethod;
 - (void)testHTTPVersion;
@@ -47,6 +48,8 @@
 - (void)testMainThreadDelegateAuthenticationFailure;
 //- (void)testCancelStressTest;
 //- (void)performCancelRequest;
+//- (void)testRedirectStressTest;
+//- (void)performRedirectRequest;
 
 @property (retain,nonatomic) ASIHTTPRequest *cancelRequest;
 @property (retain, nonatomic) NSDate *cancelStartDate;</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.h</filename>
    </modified>
    <modified>
      <diff>@@ -59,6 +59,32 @@
 	GHAssertTrue(success,@&quot;Failed to generate an error for a bad host&quot;);
 }
 
+- (void)testConditionalGET
+{
+	ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@&quot;http://allseeing-i.com/i/logo.png&quot;]];
+	[request start];
+	BOOL success = ([request responseStatusCode] == 200);
+	GHAssertTrue(success, @&quot;Failed to download file, cannot proceed with this test&quot;);
+	success = ([[request responseData] length] &gt; 0);
+	GHAssertTrue(success, @&quot;Response length is 0, this shouldn't happen&quot;);
+	
+	NSString *etag = [[request responseHeaders] objectForKey:@&quot;Etag&quot;];
+	NSString *lastModified = [[request responseHeaders] objectForKey:@&quot;Last-Modified&quot;];
+	
+	GHAssertNotNil(etag, @&quot;Response didn't return an etag&quot;);
+	GHAssertNotNil(lastModified, @&quot;Response didn't return a last modified date&quot;);
+	
+	request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@&quot;http://allseeing-i.com/i/logo.png&quot;]];
+	[request addRequestHeader:@&quot;If-Modified-Since&quot; value:lastModified];
+	[request addRequestHeader:@&quot;If-None-Match&quot; value:etag];
+	[request start];
+	success = ([request responseStatusCode] == 304);
+	GHAssertTrue(success, @&quot;Got wrong status code&quot;);
+	success = ([[request responseData] length] == 0);
+	GHAssertTrue(success, @&quot;Response length is not 0, this shouldn't happen&quot;);
+	
+}
+
 - (void)testCharacterEncoding
 {
 	
@@ -1099,6 +1125,37 @@
 //		[[self cancelRequest] startAsynchronous];
 //	}
 //}
+//
+
+// Another stress test that looks from problems when redirecting. Again, don't run on a non-local server
+
+//- (void)testRedirectStressTest
+//{
+//	[self setCancelStartDate:[NSDate dateWithTimeIntervalSinceNow:30]];
+//	[self performRedirectRequest];
+//	while ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
+//		[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
+//	}
+//	NSLog(@&quot;Redirect stress test: DONE&quot;);
+//}
+//
+//- (void)performRedirectRequest
+//{
+//	[[ASIHTTPRequest sharedRequestQueue] setMaxConcurrentOperationCount:20];
+//	[self setCancelRequest:[ASIHTTPRequest requestWithURL:[NSURL URLWithString:@&quot;http://127.0.0.1/ASIHTTPRequest/tests/one_infinite_loop&quot;]]];
+//	if ([[self cancelStartDate] timeIntervalSinceNow] &gt; 0) {
+//		NSLog(@&quot;Redirect stress test: Start request %@&quot;,[self cancelRequest]);
+//		[[self cancelRequest] startAsynchronous];
+//		[self performSelector:@selector(cancelRedirectRequest) withObject:nil afterDelay:0.2];
+//	}
+//}
+//
+//- (void)cancelRedirectRequest
+//{
+//	NSLog(@&quot;Redirect stress test: Cancel request %@&quot;,[self cancelRequest]);
+//	[[self cancelRequest] cancel];
+//	[self performRedirectRequest];
+//}
 
 
 - (void)setProgress:(float)newProgress;
@@ -1111,12 +1168,15 @@
 		NSLog(@&quot;Stress test: Cancel request %@&quot;,[self cancelRequest]);
 		[[self cancelRequest] cancel];
 		
-		[self setCancelRequest:nil];
 		[self performSelector:@selector(performCancelRequest) withObject:nil afterDelay:0.2];
+		[self setCancelRequest:nil];
 	}
 }
 
 
+
+
+
 @synthesize cancelRequest;
 @synthesize cancelStartDate;
 @end
\ No newline at end of file</diff>
      <filename>Classes/Tests/ASIHTTPRequestTests.m</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>47b4e2cc35e094799db094a74ed6d4e8dc9a5e7e</id>
    </parent>
  </parents>
  <author>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </author>
  <url>http://github.com/pokeb/asi-http-request/commit/7c0eddf2c93fe2e8f09533bee6bba57fad09d13e</url>
  <id>7c0eddf2c93fe2e8f09533bee6bba57fad09d13e</id>
  <committed-date>2009-10-30T08:59:13-07:00</committed-date>
  <authored-date>2009-10-30T08:59:13-07:00</authored-date>
  <message>Fix one more potential lock-related crash
Added additional tests  - conditional get, + new stress test
Hopefully fix 2.2.1 device+simulator builds - but I can't test the simulator build is working</message>
  <tree>36ef7942a0bda22d144bb6bfc6b41d4a066c4494</tree>
  <committer>
    <name>Ben Copsey</name>
    <email>ben@allseeing-i.com</email>
  </committer>
</commit>
