websocat icon indicating copy to clipboard operation
websocat copied to clipboard

How to specify a request body?

Open mcandre opened this issue 6 years ago • 3 comments

How can we supply an optional body, such as a JSON document, to include in a WebSocket request?

mcandre avatar Mar 19 '19 17:03 mcandre

A body with HTTP GET request?

Maybe it is possible to implement, but what is the use case? Can one supply a body when doing WebSocket connection from a browser?

In typical protocols there may be a body in separate HTTP POST request, which returns some token, which is then used for body-less HTTP GET WebSocket connection request. Example of such protocol is Google Chrome remote debugging interface.

vi avatar Mar 20 '19 10:03 vi

Some GraphQL servers (e.g. https://github.com/99designs/gqlgen) allow specifying a subscription query in the body which results in upgrading the connection to websocket.

foreverest avatar Mar 19 '21 05:03 foreverest

Is it possible to send body-containing such WebSocket request from a browser?

Currently it is problematic to do such upgrade from WebSocat.

If you can do such upgrade using some external program (e.g. like curl -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-WebSocket-Key: IQZUbZm5XwEFrOVT8+3uUw==" , but bidirectional), you can use pre-upgraded WebSocket connection with Websocat using a command line like this:

websocat -t - ws-lowlevel-client:cmd:'your_connect_and_upgrade_command'

vi avatar Mar 19 '21 07:03 vi