In our Mac application, we are creating a web-socket connection using NWConnection
and we are able to successfully establish the connection and read/write data from both sides. We have auth tokens which are sent in headers of NWProtocolWebSocket.Options
to the server. If token is good, server accepts the web-socket connection. As per RFC 6455
, if server does not want to accept the connection for any reason during web-socket handshake, it returns 403 status code. In our case, if cookies are not valid, server returns 403 during web-socket handshake.
However, we could not find a way to read this status code in Network.framework
. We are only getting failed state with NWError
which is .posix(53)
but there is no indication of the status code 403. We tried looking into protocol metadata on NWConnection
object and they are nil.
We tested the same using URLSessionWebSocketTask
where in failure callback method, we could see 403 status code on task.response
which means client is getting the code correctly from server.
So, is there a way to read the HTTP status code returned by server during web-socket handshake using Network.framework
?