Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.unstable.d.ts>Deno.upgradeHttp

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.upgradeHttp
import { Deno } from "https://deno.land/x/deno@v1.32.3/cli/tsc/dts/lib.deno.unstable.d.ts";
const { upgradeHttp } = Deno;

UNSTABLE: New API, yet to be vetted.

Allows "hijacking" the connection that the request is associated with. This can be used to implement protocols that build on top of HTTP (eg. WebSocket).

The returned promise returns underlying connection and first packet received. The promise shouldn't be awaited before responding to the request, otherwise event loop might deadlock.

function handler(req: Request): Response {
  Deno.upgradeHttp(req).then(([conn, firstPacket]) => {
    // ...
  });
  return new Response(null, { status: 101 });
}

This method can only be called on requests originating the Deno.serveHttp server.

Returns

Promise<[Deno.Conn, Uint8Array]>