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