websocket when added "upgrade" header, not being sent in headers while api is called

client code:- let resp: any = await fetch("http://127.0.0.1:8787", { headers: { Upgrade: "websocket", }, }); let ws = resp.webSocket; if (!ws) { throw new Error("server didn't accept WebSocket"); } worker code:- export default { async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { const upgradeHeader = request.headers.get('Upgrade'); if (!upgradeHeader || upgradeHeader !== 'websocket') { return new Response('Expected Upgrade: websocket', { status: 426 }); } headers does not include Upgrade header. is it something related to workers?
4 Replies
raj.js
raj.jsOP4mo ago
found the solution thanks
Devon
Devon4mo ago
What was it?
raj.js
raj.jsOP4mo ago
using the mentioed way of fetch request wasn't working, had to use WebSocket ws:// - way. i was going by the documentation at first
Devon
Devon4mo ago
Thanks!
Want results from more Discord servers?
Add your server