On Jul 14, 2014, at 3:06 AM, Daryle Walker <
email@hidden> wrote:
In “System Preferences” app, “Network” control panel, there’s an advanced setting screen for proxies? How do I get that information while implementing a NSURLProtocol?
CFNetwork has APIs for accessing proxy settings. Here’s a category method on NSURL that I wrote a while back to find the proxies relevant to that URL:
- (NSDictionary*) my_proxySettings {
CFDictionaryRef proxySettings = CFNetworkCopySystemProxySettings();
if (!proxySettings)
return nil;
NSArray* proxies = CFBridgingRelease(CFNetworkCopyProxiesForURL((__bridge CFURLRef)self,
proxySettings));
CFRelease(proxySettings);
if (proxies.count == 0)
return nil;
NSDictionary* proxy = proxies[0];
if ([proxy[(id)kCFProxyTypeKey] isEqual: (id)kCFProxyTypeNone])
return nil;
return proxy;
}
On the other hand, if you’re using NSURLConnection or NSURLSession to do the networking, those automatically check and follow the proxy settings. You only need to know about proxies if you are going to use a lower level API, like CFStream or BSD sockets, to connect.
All of the proxies except for the first two, which have “auto” in their names, have the same format: hostname, port, and optional name and password. How do you actually do proxy stuff? Is it the HTTP CONNECT command? What is different when connecting through a proxy and not using a proxy server?
It’s complicated. There are different kinds of proxies that use different protocols, and some of them require authentication. There are RFCs specifying the different types. Try to avoid directly dealing with proxies if you possibly can :-p