Skip to content

Instantly share code, notes, and snippets.

@htp
Last active April 25, 2024 14:57
Show Gist options
  • Save htp/fbce19069187ec1cc486b594104f01d0 to your computer and use it in GitHub Desktop.
Save htp/fbce19069187ec1cc486b594104f01d0 to your computer and use it in GitHub Desktop.
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/
@GeekSnail
Copy link

curl --include \
    -H "Connection: Upgrade" \
    -H "Upgrade: websocket" \
    -H "Sec-WebSocket-Key: qwerty" \
    -H "Sec-WebSocket-Version: 13" \
    https://example.com -k

@marianopeck
Copy link

Hi,

@silvioprog @jageee

I am also using this command:

curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: https://www.websocket.org" https://echo.websocket.org

but I am getting a 200 response instead of the 101.

Any ideas?

@vi
Copy link

vi commented Apr 25, 2024

  1. You need to use HTTP/1.1
  2. You have specified too few headers
$ curl --http1.1 -i -N -H 'Sec-Websocket-Version: 13' -H 'Sec-Websocket-Key: QUo86XL2bHszCCpigvKqHg==' -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: https://www.websocket.org" https://echo.websocket.org
HTTP/1.1 101 Switching Protocols
upgrade: websocket
connection: Upgrade
sec-websocket-accept: 8dlVwoWynsF/RauFo6HjkWl7dLk=
date: Thu, 25 Apr 2024 14:28:01 GMT
server: Fly/610c12e9 (2024-04-23)
via: 1.1 fly.io
fly-request-id: 01HWATFYXA0Y3STERG1SCHNQS2-ams

 Request served by 7811941c69e658

@marianopeck
Copy link

Thanks @vi that worked perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment