vbmithr / ocaml-websocket

Websocket library for OCaml
ISC License
161 stars 44 forks source link

Lwt example fails with "Bad headers" when connecting from Firefox #119

Open olleharstedt opened 4 years ago

olleharstedt commented 4 years ago

I compile the lwt example and run it with

./a.out -s -loglevel 3 http://127.0.0.1:8888

From the browser (Firefox) I run

var ws = new WebSocket("ws://127.0.0.1:8888");

The browser fails with

Firefox can’t establish a connection to the server at ws://127.0.0.1:8888/.

and the server with

Fatal error: exception Websocket.Protocol_error("Bad headers")

Any ideas what's wrong?

olleharstedt commented 4 years ago

Using wss from browser gives another result, but it still explodes

Fatal error: exception Websocket_lwt_unix.HTTP_Error("Malformed request HTTP version: \139\150V\174\221\217\128E+A=\238\160\197$\154\027\157")

roddyyaga commented 4 years ago

I had the same problem when I set up a server with Websocket_lwt_unix.establish_standard_server ~mode handler and tested it from Firefox/Chrome extensions. The problem was the call to check_request failing because the origin header was chrome-extension://... which didn't match the host. I fixed this by calling establish_standard_server with ~check_request:(fun _ -> true).