Julien Genestoux Julien Genestoux - 6 days ago 4x
HTTP Question

HTTP headers in Websockets client API

Looks like it's easy to add custom HTTP headers to your websocket client with any HTTP header client which supports this, but I can't find how to do it with the JSON API.

Yet, it seems that there should be support these headers in the spec.

Anyone has a clue on how to achieve it?

var ws = new

Specially, I need to be able to send an HTTP Authorization header.



There is no existing method in the JavaScript WebSockets API for specifying additional headers for the client/browser to send. The only headers that the client can influence are the resource-name/path (in the URI) and the WebSocket-Protocol header. The WebSocket-Protocol header is generated from the optional second argument when a WebSocket object is created:

var ws = new WebSocket("ws://example.com/path", "protocol-name");