First steps with Websockets (HTTP exception: invalid scheme ws)

Hi guys.

I am relatively new to the subject. I am sending several websocket requests through the MITM proxy (running in regular/default mode) and getting the following error from (I presume) the proxy:

HTTP 400 Bad Request
HttpException: Invalid Request Scheme ws

This is the request with the response:

Request DefaultFullHttpRequest(decodeResult: success, version: HTTP/1.1, content: EmptyByteBufBE)
GET ws://localhost:9000/listen HTTP/1.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
DNT: 1
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
User-Agent: Gatling2
Upgrade: WebSocket
Connection: Upgrade
Origin: http://localhost:9000
Sec-WebSocket-Key: zf4TRZ9uK8O7EUaCHfdUPA==
Sec-WebSocket-Version: 13
Host: localhost:9000

Response DefaultHttpResponse(decodeResult: success, version: HTTP/1.1)
HTTP/1.1 400 Bad Request
Server: mitmproxy 3.0.0
Connection: close
Content-Length: 258
Content-Type: text/html

Any ideas, please?

Hi,

Is GET ws://localhost:9000/listen HTTP/1.1 valid HTTP? I believe that should be http:// in there, but I’m happy to be corrected if you can point me to a relevant RFC section.

Oh, you caught me rather off guard with that one.

I am sending the requests with Gatling, which does not seem itself that well RFC-compliant.
According to https://tools.ietf.org/html/rfc6455, the opening line should not contain the protocol and domain at all:

For example, if the WebSocket URI is “ws://example.com/chat”,
the first line sent should be “GET /chat HTTP/1.1”.

This looks like an issue with Gatling. Thanks for pointing out!

I rewrote the client code to fit the RFC specs and it all passed fluently - this issue can be closed.

Thanks!

1 Like