Re: Implementing proxy support
Re: Implementing proxy support
- Subject: Re: Implementing proxy support
- From: Daryle Walker <email@hidden>
- Date: Tue, 15 Jul 2014 01:34:59 -0400
On Jul 14, 2014, at 12:17 PM, Jens Alfke <email@hidden> wrote:
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.
I’m in the middle. It’s a NSURLProtocol subclass, which NSURLConnection/Session use to do their dirty work. So I have to implement the “automatic" check and proxy setting following, probably involving CFStream or BSD sockets. Hopefully not the latter, since I’m a newbie.
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
I don’t know which one(s) I need yet. What proxy styles were the Networking authors envisioning for the entries in the control panel?
— Daryle Walker Mac, Internet, and Video Game Junkie darylew AT mac DOT com
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden