Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify a request body? #40

Open
mcandre opened this issue Mar 19, 2019 · 3 comments
Open

How to specify a request body? #40

mcandre opened this issue Mar 19, 2019 · 3 comments

Comments

@mcandre
Copy link

mcandre commented Mar 19, 2019

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

@vi
Copy link
Owner

vi commented Mar 20, 2019

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.

@foreverest
Copy link

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.

@vi
Copy link
Owner

vi commented Mar 19, 2021

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'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants