I'm using [NSStream getStreamsToHost:port:inputStream:outputStream:] to create a new stream to a web server to stream generated data on the fly. How would I go about setting up the NSStream to use the system HTTP proxy like NSURLConnection does? I can't find any info on how to lookup the system proxy, so far all I've discovered is how to setup a known SOCKS proxy against the stream.
Thanks, J
Disclaimer:
NSStream/CF(Read|Write)StreamRefAPIs.With that out of the way, the way to go appears to be using the
SystemConfiguration-framework — namely the functionSCDynamicStoreCopyProxies.This function returns a
CFDictionaryRef, which can then be set as the stream'skCFStreamPropertyHTTPProxy-property (any other proxy type should work by using the protocol's equivalent key).I don't know yet, whether it is imperative to set this property on the CoreFoundation-level or if using
-[NSStream setProperty:forKey:]is possible, as well — I strongly assume the latter, but again: I more or less started seriously looking into these APIs today…Anyway, there's a section called "Navigating Firewalls" covering this stuff in Apple's CFNetworking Programming Guide—which describes this more detailed.
Update
In case anyone is still interested in this, there's an API which I managed to not find, the whole weekend.
On iOS, the
SCDynamicStoreAPIs (which are referred to in the link I posted) do not exist. There is, however, another API which has been around since iOS 2.0 and is present on OS X since 10.6:CFProxySupportAlthough
CFProxySupportis part of theCFNetworkframework, it isn't mentioned anywhere in the "CFNetwork Programming Guide" — which is a shame because it's simple and pleasant to use.Filed a bug with Apple's docs (rdar://problem/10491759)