Hey Jens, I can't really answer about upgrading the data task to a stream task as I haven't tried that, but:
- Constructing and parsing HTTP messages can be done with CFHTTPMessageCreateRequest/Response - Stream tasks do handle SSL for you (with -startSecureConnection) - Stream tasks handle proxies but only SOCKS :-( — I've filled a bug to request HTTP proxies, if you go that route, you should too. - Stream tasks do handle auth challenges via NSURLSession's delegate, and its own delegate as well - You probably do have to handle redirects yourself indeed. So while it would be good if someone has an answer for your NSURLSessionDataTask to NSURLSessionStreamTask problem, if there are no proper ways of doing it, you could still handle some of it yourself. I disagree that NSURLSessionStreamTask is no better than NSStream: it is much better and easier :-). In fact, NSURLSessionStreamTask is built using NSStream-s! On Tue, 14 Mar 2017 at 22:36 Jens Alfke <j...@mooseyard.com> wrote: > So I’ve been hoping that NSURLSessionStreamTask would make it easier to > implement WebSockets by allowing me to make the initial HTTP handshake as a > regular HTTP request with an NSURLSessionDataTask, then switch to a raw > stream by returning NSURLSessionResponseBecomeStream from the response > delegate method. > > I just tried it (on macOS 10.12.4 beta 4) and unfortunately it doesn’t > work. Upgrading protocols requires that the value of the request's > “Connection:” header be “Upgrade", but the value gets changed to > “keep-alive” when sent, causing the server to reject the request. I assume > this is one of those headers that the client can’t control. :( > > I can instead create the task as a stream from the beginning by calling > -streamTaskWithHostName:port:. But then I’m basically working with raw TCP, > so I need to construct and parse the HTTP messages myself, and more > importantly, I lose SSL support and the semi-automatic handling of proxies, > redirects and auth challenges. (It’s really no better than NSStream.) > > Is this something that could be fixed in the future, or is it considered a > non-feature for NSURLSession to allow HTTP connection upgrades? > > —Jens > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > > https://lists.apple.com/mailman/options/macnetworkprog/thibault.ml%40gmail.com > > This email sent to thibault...@gmail.com -- Thibault ML
_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com This email sent to arch...@mail-archive.com