Julien Genestoux Julien Genestoux - 1 year ago 90
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.

Answer Source


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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download