blaze icon indicating copy to clipboard operation
blaze copied to clipboard

Testing websocket responses

Open siers opened this issue 5 years ago • 3 comments

Is this possible currently? I took a look at how the regular HTTP responses can be tested by feeding a response to the HttpRoutes object, but when feeding the same response I get a 501 response in status code.

I tried seeing the source for how tests are doing it and whether Request definition has some clues, but no clues jumped out at me. 😛

Any suggestions would be appreciated by me and perhaps by other people hopefully stumbling upon this later by googling.

siers avatar Mar 15 '20 16:03 siers

The 501 is the default onNonWebSocketRequest in the WebSocketBuilder. The response should have a WebSocketContext attribute with key org.http4s.server.websocketKey. The WebSocketContext contains the WebSocket, that you can interact with via send and receive.

There's no helper I know of that digs through this, or implements client logic like responding to pings with pongs or doing the close handshake. A helper, or at least an example, for this would be great.

rossabaker avatar Mar 16 '20 03:03 rossabaker

The response should have a WebSocketContext attribute

Should the "response" have been "request" here or no?

siers avatar Mar 16 '20 13:03 siers

No, response. When you post to a web socket route, you get back a response with an attribute that represents the server's view of the web socket. You can then interact with the send and receive on that web socket to act as the client.

rossabaker avatar Mar 17 '20 03:03 rossabaker