Bad Handshake issue when using Secure Web Sockets

Hi, I’m using K6 (.25 version) to perform load testing on a WSS url. I’m getting the Bad Handshake issue and I coudn’t find much information on whether K6 supports Secure Web Sockets (WSS). Can you please help if there is any workaround to make K6 support WSS

INFO[0003] An unexpected error occured: 0=“websocket: bad handshake”
ERRO[0003] GoError: websocket: bad handshake-
at native

Thanks in advance.



k6 does support WSS. The example found here also works if you use the WSS endpoint (wss://echo.websocket.org).

Looking at the source code of the WS library used by k6, this error is returned if the server returns an invalid response to an Upgrade request. So make sure that the server you’re testing is sending a compliant response.

Thanks much Ivan for the reply.

I tried with the very same example. I’m able to successfully connect with the Chrome Web Socket Client plugin.

How can we enable some debugging on this to know the request and response from the server?

k6 has an --http-debug option, but unfortunately no equivalent for WebSockets. See this FAQ for details.

You could attempt --http-debug with a manually crafted Upgrade request like so:

import http from "k6/http";

export default function () {
   http.get("http://echo.websocket.org", {
       headers: {
           "Connection": "Upgrade",
           "Upgrade": "websocket",
           "Sec-WebSocket-Key": "1WKeF1XWzkUXPHzXiYAKCg==",

… but I wasn’t able to get a valid 101 response, so YMMV.

Alternatively, you can use a TCP/HTTP tracing tool like tcpdump, Wireshark or Sysdig to record and visualize the request/response.

I’m able to make it work by explicitly sending the ‘Origin’ field in header ,

Is it something K6 can add in future releases?


Glad that you got it working.

Setting the ‘Origin’ header would be outside of k6 concerns, since it’s application-specific, and you can set it manually, as you’ve seen.