Fix problem where redirected requests would store the body of the first response…
… rather than the last Closes #18 Copied requests now remember redirect behaviour Fix typos in comments
Showing
3 changed files
with
16 additions
and
6 deletions
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | // ASIHTTPRequest.h | 2 | // ASIHTTPRequest.h |
3 | // | 3 | // |
4 | // Created by Ben Copsey on 04/10/2007. | 4 | // Created by Ben Copsey on 04/10/2007. |
5 | -// Copyright 2007-2009 All-Seeing Interactive. All rights reserved. | 5 | +// Copyright 2007-2010 All-Seeing Interactive. All rights reserved. |
6 | // | 6 | // |
7 | // A guide to the main features is available at: | 7 | // A guide to the main features is available at: |
8 | // http://allseeing-i.com/ASIHTTPRequest | 8 | // http://allseeing-i.com/ASIHTTPRequest |
@@ -298,7 +298,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -298,7 +298,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
298 | // Incremented every time this request redirects. When it reaches 5, we give up | 298 | // Incremented every time this request redirects. When it reaches 5, we give up |
299 | int redirectCount; | 299 | int redirectCount; |
300 | 300 | ||
301 | - // When NO, requests will not check the secure certificate is valid (use for self-signed cerficates during development, DO NOT USE IN PRODUCTION) Default is YES | 301 | + // When NO, requests will not check the secure certificate is valid (use for self-signed certificates during development, DO NOT USE IN PRODUCTION) Default is YES |
302 | BOOL validatesSecureCertificate; | 302 | BOOL validatesSecureCertificate; |
303 | 303 | ||
304 | // Details on the proxy to use - you could set these yourself, but it's probably best to let ASIHTTPRequest detect the system proxy settings | 304 | // Details on the proxy to use - you could set these yourself, but it's probably best to let ASIHTTPRequest detect the system proxy settings |
@@ -313,7 +313,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -313,7 +313,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
313 | 313 | ||
314 | // When YES, ASIHTTPRequests will present credentials from the session store for requests to the same server before being asked for them | 314 | // When YES, ASIHTTPRequests will present credentials from the session store for requests to the same server before being asked for them |
315 | // This avoids an extra round trip for requests after authentication has succeeded, which is much for efficient for authenticated requests with large bodies, or on slower connections | 315 | // This avoids an extra round trip for requests after authentication has succeeded, which is much for efficient for authenticated requests with large bodies, or on slower connections |
316 | - // Set to NO to only present credentials when explictly asked for them | 316 | + // Set to NO to only present credentials when explicitly asked for them |
317 | // This only affects credentials stored in the session cache when useSessionPersistance is YES. Credentials from the keychain are never presented unless the server asks for them | 317 | // This only affects credentials stored in the session cache when useSessionPersistance is YES. Credentials from the keychain are never presented unless the server asks for them |
318 | // Default is YES | 318 | // Default is YES |
319 | BOOL shouldPresentCredentialsBeforeChallenge; | 319 | BOOL shouldPresentCredentialsBeforeChallenge; |
@@ -335,7 +335,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | @@ -335,7 +335,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount; | ||
335 | // The number of times this request has retried (when numberOfTimesToRetryOnTimeout > 0) | 335 | // The number of times this request has retried (when numberOfTimesToRetryOnTimeout > 0) |
336 | int retryCount; | 336 | int retryCount; |
337 | 337 | ||
338 | - // When YES, requests will keep the connection to the server alive for a while to allow subsequent requests to re-use it for a substatial speed-boost | 338 | + // When YES, requests will keep the connection to the server alive for a while to allow subsequent requests to re-use it for a substantial speed-boost |
339 | // Persistent connections only work when the server sends a 'Keep-Alive' header | 339 | // Persistent connections only work when the server sends a 'Keep-Alive' header |
340 | // Default is YES | 340 | // Default is YES |
341 | BOOL shouldAttemptPersistentConnection; | 341 | BOOL shouldAttemptPersistentConnection; |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | // ASIHTTPRequest.m | 2 | // ASIHTTPRequest.m |
3 | // | 3 | // |
4 | // Created by Ben Copsey on 04/10/2007. | 4 | // Created by Ben Copsey on 04/10/2007. |
5 | -// Copyright 2007-2009 All-Seeing Interactive. All rights reserved. | 5 | +// Copyright 2007-2010 All-Seeing Interactive. All rights reserved. |
6 | // | 6 | // |
7 | // A guide to the main features is available at: | 7 | // A guide to the main features is available at: |
8 | // http://allseeing-i.com/ASIHTTPRequest | 8 | // http://allseeing-i.com/ASIHTTPRequest |
@@ -21,7 +21,7 @@ | @@ -21,7 +21,7 @@ | ||
21 | #import "ASIInputStream.h" | 21 | #import "ASIInputStream.h" |
22 | 22 | ||
23 | // Automatically set on build | 23 | // Automatically set on build |
24 | -NSString *ASIHTTPRequestVersion = @"v1.5-39 2010-02-02"; | 24 | +NSString *ASIHTTPRequestVersion = @"v1.5-40 2010-02-02"; |
25 | 25 | ||
26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 26 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
27 | 27 | ||
@@ -2511,6 +2511,7 @@ static BOOL isiPhoneOS2; | @@ -2511,6 +2511,7 @@ static BOOL isiPhoneOS2; | ||
2511 | // Close the output stream as we're done writing to the file | 2511 | // Close the output stream as we're done writing to the file |
2512 | if ([self temporaryFileDownloadPath]) { | 2512 | if ([self temporaryFileDownloadPath]) { |
2513 | [[self fileDownloadOutputStream] close]; | 2513 | [[self fileDownloadOutputStream] close]; |
2514 | + [self setFileDownloadOutputStream:nil]; | ||
2514 | 2515 | ||
2515 | // Decompress the file (if necessary) directly to the destination path | 2516 | // Decompress the file (if necessary) directly to the destination path |
2516 | if ([self isResponseCompressed]) { | 2517 | if ([self isResponseCompressed]) { |
@@ -2722,6 +2723,7 @@ static BOOL isiPhoneOS2; | @@ -2722,6 +2723,7 @@ static BOOL isiPhoneOS2; | ||
2722 | [newRequest setPACurl:[self PACurl]]; | 2723 | [newRequest setPACurl:[self PACurl]]; |
2723 | [newRequest setShouldPresentCredentialsBeforeChallenge:[self shouldPresentCredentialsBeforeChallenge]]; | 2724 | [newRequest setShouldPresentCredentialsBeforeChallenge:[self shouldPresentCredentialsBeforeChallenge]]; |
2724 | [newRequest setNumberOfTimesToRetryOnTimeout:[self numberOfTimesToRetryOnTimeout]]; | 2725 | [newRequest setNumberOfTimesToRetryOnTimeout:[self numberOfTimesToRetryOnTimeout]]; |
2726 | + [newRequest setShouldUseRFC2616RedirectBehaviour:[self shouldUseRFC2616RedirectBehaviour]]; | ||
2725 | return newRequest; | 2727 | return newRequest; |
2726 | } | 2728 | } |
2727 | 2729 |
@@ -378,6 +378,14 @@ | @@ -378,6 +378,14 @@ | ||
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | + // Ensure the file contains only the body of the last request (after redirects) when downloading to a file | ||
382 | + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/redirect/301"]]; | ||
383 | + NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"test.txt"]; | ||
384 | + [request setDownloadDestinationPath:path]; | ||
385 | + [request startSynchronous]; | ||
386 | + NSString *result = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil]; | ||
387 | + success = [result isEqualToString:@"Redirected as GET after a 301 status code"]; | ||
388 | + GHAssertTrue(success,@"Failed to store just the body of the file request on redirect"); | ||
381 | } | 389 | } |
382 | 390 | ||
383 | // Using a persistent connection for HTTP 305-307 would cause crashes on the redirect, not really sure why | 391 | // Using a persistent connection for HTTP 305-307 would cause crashes on the redirect, not really sure why |
-
Please register or login to post a comment