- (BOOL)configureProxies { // Have details of the proxy been set on this request if (![self isPACFileRequest] && (![self proxyHost] && ![self proxyPort])) { // If not, we need to figure out what they'll be NSArray *proxies = nil; // Have we been given a proxy auto config file? if ([self PACurl]) { // If yes, we'll need to fetch the PAC file asynchronously, so we stop this request to wait until we have the proxy details. [self fetchPACFile]; return NO; // Detect proxy settings and apply them } else { #if TARGET_OS_IPHONE NSDictionary *proxySettings = [NSMakeCollectable(CFNetworkCopySystemProxySettings()) autorelease]; #else NSDictionary *proxySettings = [NSMakeCollectable(SCDynamicStoreCopyProxies(NULL)) autorelease]; #endif proxies = [NSMakeCollectable(CFNetworkCopyProxiesForURL((CFURLRef)[self url], (CFDictionaryRef)proxySettings)) autorelease]; // Now check to see if the proxy settings contained a PAC url, we need to run the script to get the real list of proxies if so NSDictionary *settings = [proxies objectAtIndex:0]; if ([settings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]) { [self setPACurl:[settings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]]; [self fetchPACFile]; return NO; } } if (!proxies) { [self setReadStream:nil]; [self failWithError:[NSError errorWithDomain:NetworkRequestErrorDomain code:ASIInternalErrorWhileBuildingRequestType userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"Unable to obtain information on proxy servers needed for request",NSLocalizedDescriptionKey,nil]]]; return NO; } // I don't really understand why the dictionary returned by CFNetworkCopyProxiesForURL uses different key names from CFNetworkCopySystemProxySettings/SCDynamicStoreCopyProxies // and why its key names are documented while those we actually need to use don't seem to be (passing the kCF* keys doesn't seem to work) if ([proxies count] > 0) { NSDictionary *settings = [proxies objectAtIndex:0]; [self setProxyHost:[settings objectForKey:(NSString *)kCFProxyHostNameKey]]; [self setProxyPort:[[settings objectForKey:(NSString *)kCFProxyPortNumberKey] intValue]]; [self setProxyType:[settings objectForKey:(NSString *)kCFProxyTypeKey]]; } } return YES; }