Skip to content

Accept arbitrary request headers for WebSocketStream API #11847

@danopia

Description

@danopia

The options bag accepted by WebSocketStream should be extended to accept a dictionary/Headers of custom HTTP headers. This would enable sending authorization headers and/or cookies.

For context, the web browser security model treats WebSockets like <img> tags. This means that the user agent fully decides the headers to send. Thus, unlike fetch(), the upstream WebSocket and WebSocketStream specs does not allow for customizing the HTTP request.

The proposal here is that Deno add arbitrary header support out-of-spec. I'm specifically referring to WebSocketStream as it has an options bag already and is a more useful API for modern stream-oriented programming.

Brief example code

const ws = new WebSocketStream("https://myserver.com", {
  headers: {
    authorization: `Bearer ${jwt}`,
  },
});

Discussed in #9891

Originally posted by scientific-dev March 25, 2021
I am working with an socket api where i need to send headers with the socket connections. However in nodejs it allows me to input headers in the second param. But as deno uses the browser like WebSocket api. I can't send headers with it. Any way so how can i send it with deno?

Further background: #9890 and whatwg/websockets#16

Metadata

Metadata

Assignees

Labels

ext/websocketrelated to the ext/websocket cratesuggestionsuggestions for new features (yet to be agreed)webrelated to Web APIs

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions