Post

Replies

Boosts

Views

Activity

Reply to Network.framework (websocket): read response headers set by the server
 I looked into additionalServerHeaders a bit and this does certainly look like something you can add on the client side of the connection Reading the documentation, additionalServerHeaders is supposed to contain “additional HTTP headers sent by the server during the WebSocket handshake.”; I don't think they can be set client side. (But I'm totally new to the framework so I trust your words much more than my assumptions). To give you more context: If, client side, I set some headers: let wsOptions = NWProtocolWebSocket.Options() wsOptions.setAdditionalHeaders([("custom-client-header", "test-client”)]) I’m able to retrieve them server side (the test server is implemented with Network.framework locally), like so: let wsOptions = NWProtocolWebSocket.Options() wsOptions.setClientRequestHandler(serverQueue) { (_, headers) -> NWProtocolWebSocket.Response in print(headers) /* [(name: "custom-client-header", value: "test-client"), (name: "Host", value: "localhost")] ✅ */ 		let additionalServerHeaders = [("custom-server-header", “test-server”)] /* set some custom headers */ 		return.init(status: .accept, subprotocol: nil, additionalHeaders: additionalServerHeaders) } At this point, since I’ve set new headers server side during the handshake, I thought I could access them client side somehow: My first try (client side) was: connection = NWConnection(…) connection.stateUpdateHandler = { [weak self] state in guard let self = self else { return } /* the cast to NWProtocolWebSocket.Metadata always fails */ if let metadata = self.connection.metadata(definition: NWProtocolWebSocket.definition) as? NWProtocolWebSocket.Metadata { 				print(metadata.additionalServerHeaders) 		} } My second one was: connection.receiveMessage { [weak self] (data, context, isComplete, error) in if let context = context, let metadata = context.protocolMetadata.first as? NWProtocolWebSocket.Metadata { print(metadata.additionalServerHeaders) /* nil */ 	} } In short: I didn't find a way to proper access the NWProtocolWebSocket.Metadata additionalServerHeaders. Again, thank you for spending your time looking into this.
Oct ’20
Reply to Network.framework (websocket): read response headers set by the server
Thanks for the suggestions; I will certanly look into them. I am not aware of any way to do this during the handshake.  Ok, I thought it could be possible using the additionalServerHeaders - https://developer.apple.com/documentation/network/nwprotocolwebsocket/metadata/3200532-additionalserverheaders defined in the NWProtocolWebSocket.Metadata. Please follow up with your Feedback ID. FB8782882
Oct ’20