Replies: 4 comments
-
It looks like according to this post headers aren't generally supported in WebSockets. The node.js implementation may allow additional options though. So, this might make sense in the future, but requires more investigation before making any changes to what is passed to the underlying library. It would require abstracting the I don't think the changes in the PR are sufficient though, since the values aren't actually passed through to the underlying WebSocket. But I'll look into it. :) |
Beta Was this translation helpful? Give feedback.
-
I've secured my websocket with basic auth so would be nice to set custom headers... not this is not good practice, what else do you recommend? |
Beta Was this translation helpful? Give feedback.
-
Oh wow. This is an old post, that I should close since this is now supported using a Socket creator function: // A function that returns a websocket; it can configure anything it wishes and will be called whenever the Provider has to reconnect
const socketFunc = ()=> {
// custom setup, headers, etc.
const ws = new WebSocket(url, etc);
// ws.on(somethingSpecial, etc)
return ws;
};
const provider = new WebSocketProvider(socketFunc); Does that work for you? :) |
Beta Was this translation helpful? Give feedback.
-
(moving to discussions) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
WebSocketProvider
constructor signature reduces the types accepted by its parent classJsonRpcProvider
, and makes it harder to use it in places where I was using a JsonRpcProvider before.This is the constructor of the
JsonRpcProvider
class:It takes a
ConnectionInfo
object, useful for adding headers to each HTTP request (and I need this).while this is the constructor of the
WebSocketProvider
class:It takes only a string, thus it's impossibile to pass additional options for the WS connection.
It's not a limitation of the underlying
WebSocket
lib, because it accepts a wealth of options, including custom headers. See its constructor here:I've not checked every possible option, but I think most of the props in the
ConnectionInfo
type can be mapped to WS ones. At least I'm sure that theheaders
one can be mapped exactly as is for the WebSocket class. See this snippet fromWebSocket
as a proof:I propose to refactor the
WebSocketProvider
constructor to accept aConnectionInfo
param like its parent, and map it props to the correspondingWebSocket
options.Reproduction steps
Try to construct a
WebSocketProvider
using aConnectionInfo
object, and of course it'll fail...Environment:
N/A
Search Terms
WebSocketProvider
Beta Was this translation helpful? Give feedback.
All reactions