Ben Copsey

Assume no proxy if PAC could not be read

... ... @@ -2868,7 +2868,9 @@ static BOOL isiPhoneOS2;
NSError *err = nil;
NSString *script = [NSString stringWithContentsOfURL:pacScriptURL usedEncoding:&encoding error:&err];
if (err) {
return nil;
// If we can't fetch the PAC, we'll assume no proxies
// Some people have a PAC configured that is not always available, so I think this is the best behaviour
return [NSArray array];
}
// Obtain the list of proxies by running the autoconfiguration script
#if TARGET_IPHONE_SIMULATOR && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_3_0
... ...
... ... @@ -20,11 +20,19 @@ static NSString *proxyPassword = @"";
- (void)testAutoConfigureWithPAC
{
// To run this test, specify the location of the pac script that is available at http://developer.apple.com/samplecode/CFProxySupportTool/listing1.html
NSString *pacurl = @"file:///Users/ben/Desktop/test.pac";
NSString *pacurl = @"file:///non-existent.pac";
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setPACurl:[NSURL URLWithString:pacurl]];
[request start];
GHAssertNil([request proxyHost],@"Shouldn't use a proxy here");
GHAssertNil([request error],@"Request failed when unable to fetch PAC (should assume no proxy instead)");
// To run this test, specify the location of the pac script that is available at http://developer.apple.com/samplecode/CFProxySupportTool/listing1.html
pacurl = @"file:///Users/ben/Desktop/test.pac";
request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setPACurl:[NSURL URLWithString:pacurl]];
[request start];
BOOL success = [[request proxyHost] isEqualToString:@"proxy1.apple.com"];
GHAssertTrue(success,@"Failed to use the correct proxy");
... ...