Open NuroDev opened 2 months ago
Hello @NuroDev
Currently, WebSocket API in JavaScript doesn't support sending headers. WebSocket
constructor supports only URL and protocol.
RPC Client uses WebSocket API, so I think we can't resolve it. However writing about it to docs is good idea.
Reference:
Oh, sorry, I missed a fact.
WebSocket
in Bun accepts headers.
Interesting, good point @nakasyou. After a bit more digging I found this issue created 7 years asking for this to become a standard. However Bun seems to have gone ahead and added support for it anyway.
What version of Hono are you using?
4.4.3
What runtime/platform is your app running on?
Bun
What steps can reproduce the bug?
What is the expected behavior?
Based on the example above:
c.req.header('Authorization')
should return'Bearer 123'
.What do you see instead?
Based on the example above:
c.req.header('Authorization')
instead returnsundefined
.Additional information
I of course did a quick look into this and this line seems to be the cause. We just need to pass
args
as a 2nd argument when creating the new websocket instance.At a basic level the
const args = ...
could just be moved up & used for bothreq.fetch(...)
andnew WebSocket(...)
but I don't know if there is any issue with exposing all arguments when creating the new websocket instance, or if it should be limited to just headers?