Ben Copsey

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
... ... @@ -2,7 +2,7 @@
// ASIHTTPRequest.h
//
// Created by Ben Copsey on 04/10/2007.
// Copyright 2007-2009 All-Seeing Interactive. All rights reserved.
// Copyright 2007-2010 All-Seeing Interactive. All rights reserved.
//
// A guide to the main features is available at:
// http://allseeing-i.com/ASIHTTPRequest
... ... @@ -298,7 +298,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
// Incremented every time this request redirects. When it reaches 5, we give up
int redirectCount;
// 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
// 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
BOOL validatesSecureCertificate;
// 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;
// When YES, ASIHTTPRequests will present credentials from the session store for requests to the same server before being asked for them
// 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
// Set to NO to only present credentials when explictly asked for them
// Set to NO to only present credentials when explicitly asked for them
// 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
// Default is YES
BOOL shouldPresentCredentialsBeforeChallenge;
... ... @@ -335,7 +335,7 @@ extern unsigned long const ASIWWANBandwidthThrottleAmount;
// The number of times this request has retried (when numberOfTimesToRetryOnTimeout > 0)
int retryCount;
// 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
// 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
// Persistent connections only work when the server sends a 'Keep-Alive' header
// Default is YES
BOOL shouldAttemptPersistentConnection;
... ...
... ... @@ -2,7 +2,7 @@
// ASIHTTPRequest.m
//
// Created by Ben Copsey on 04/10/2007.
// Copyright 2007-2009 All-Seeing Interactive. All rights reserved.
// Copyright 2007-2010 All-Seeing Interactive. All rights reserved.
//
// A guide to the main features is available at:
// http://allseeing-i.com/ASIHTTPRequest
... ... @@ -21,7 +21,7 @@
#import "ASIInputStream.h"
// Automatically set on build
NSString *ASIHTTPRequestVersion = @"v1.5-39 2010-02-02";
NSString *ASIHTTPRequestVersion = @"v1.5-40 2010-02-02";
NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";
... ... @@ -2511,6 +2511,7 @@ static BOOL isiPhoneOS2;
// Close the output stream as we're done writing to the file
if ([self temporaryFileDownloadPath]) {
[[self fileDownloadOutputStream] close];
[self setFileDownloadOutputStream:nil];
// Decompress the file (if necessary) directly to the destination path
if ([self isResponseCompressed]) {
... ... @@ -2722,6 +2723,7 @@ static BOOL isiPhoneOS2;
[newRequest setPACurl:[self PACurl]];
[newRequest setShouldPresentCredentialsBeforeChallenge:[self shouldPresentCredentialsBeforeChallenge]];
[newRequest setNumberOfTimesToRetryOnTimeout:[self numberOfTimesToRetryOnTimeout]];
[newRequest setShouldUseRFC2616RedirectBehaviour:[self shouldUseRFC2616RedirectBehaviour]];
return newRequest;
}
... ...
... ... @@ -378,6 +378,14 @@
}
}
// Ensure the file contains only the body of the last request (after redirects) when downloading to a file
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/redirect/301"]];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"test.txt"];
[request setDownloadDestinationPath:path];
[request startSynchronous];
NSString *result = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
success = [result isEqualToString:@"Redirected as GET after a 301 status code"];
GHAssertTrue(success,@"Failed to store just the body of the file request on redirect");
}
// Using a persistent connection for HTTP 305-307 would cause crashes on the redirect, not really sure why
... ...