oak: Upgrading to native WebSocket fails

Running Deno 1.12.1, oak 8.0.0. The following code:

console.log(context.isUpgradable);
return context.upgrade();

produces the following output and error:

true
TypeError: Invalid Header: 'connection' header must be 'Upgrade'
    at Object.upgradeWebSocket (deno:extensions/http/01_http.js:325:13)
    at NativeRequest.upgrade (https://deno.land/x/oak@v8.0.0/http_server_native.ts:159:59)
    at Context.upgrade (https://deno.land/x/oak@v8.0.0/context.ts:198:51)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I think I found the cause of this issue.

Deno.upgradeWebSocket returns a property called socket, but NativeRequest.upgrade tries to unpack the websocket property.

https://github.com/denoland/deno/blob/ba8bbe6f1c11d4cf19ad0b916ba41cd919dbb042/ext/http/01_http.js#L398 https://github.com/oakserver/oak/blob/bcde4bee6b65cc7291694541839ec2dd5bf13a7b/http_server_native.ts#L160

Edit: the breakage seems to have been caused by https://github.com/denoland/deno/pull/11542

@kitsonk sorry for coming back on this issue, but I still can’t upgrade a WebSocket with Deno 1.14.1 and Oak 9.0.1 and NGINX in front of my app:

[uncaught application error]: Http - no upgrade available

It’s related to what I was saying on August 14 about NGINX transforming header names to lowercase, which apparently is normal behavior for HTTP/2.

Upgrading to a WebSocket works fine when the connection header’s value is Upgrade but not when it’s upgrade.

I’m not sure who to turn to with this. I haven’t been able to upgrade either Deno or Oak for 2 months now, it’s frustrating…

@lucacasonato Same problem, with an additional one:

context.upgrade().then((socket) => console.log(socket));

socket is undefined with Deno 1.13.0 and canary.

The issue with a header like:

Connection: keep-alive, Upgrade

Was fixed after 1.12.2 and later (denoland/deno#11505).

That is why I am asking for what specifically the connection header looks like. oak doesn’t touch the header, so it is still very unlikely to be an oak issue.