Re: Using NSURLSessionStreamTask for WebSockets
Re: Using NSURLSessionStreamTask for WebSockets
- Subject: Re: Using NSURLSessionStreamTask for WebSockets
- From: Jens Alfke <email@hidden>
- Date: Tue, 14 Mar 2017 17:17:00 -0700
On Mar 14, 2017, at 3:36 PM, I wrote:
Is this something that could be fixed in the future, or is it considered a non-feature for NSURLSession to allow HTTP connection upgrades?
Responding to my own post: The following comment from NSURLSession.h strongly implies that it’s _intended to_ support WebSocket upgrades:
Beginning with iOS 9 and Mac OS X 10.11, NSURLSessionStream is available as a task type. This allows for direct TCP/IP connection to a given host and port with optional secure handshaking and navigation of proxies. Data tasks may also be upgraded to a NSURLSessionStream task via the HTTP Upgrade: header and appropriate use of the pipelining option of NSURLSessionConfiguration. See RFC 2817 and RFC 6455 for information about the Upgrade: header, and comments below on turning data tasks into stream tasks.
Note that RFC 6455 is the WebSocket spec. However, that RFC’s description of the required client handshake includes “Connection: upgrade”, and the HTTP 1.1 spec (RFC 7230, sec. 6.7) states:
When Upgrade is sent, the sender MUST also send a Connection header field … that contains an "upgrade" connection option
so this looks like a bug in NSURLSession.
I experimentally tried disabling the check for ‘Connection: upgrade’ in my WebSocket server, and then I was able to perform a protocol upgrade using NSURLSession. But that’s not going to work well in the real world. :(
—Jens |
_______________________________________________
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