function isWebSocketUpgradeRequest
Since 0.3.0
isWebSocketUpgradeRequest(headers: Headers): boolean

Reports whether a set of request headers describes an RFC 6455 WebSocket upgrade.

Both conditions are required, per RFC 6455 §4.2.1: Upgrade must equal websocket (case-insensitively), and Connection must contain the upgrade token. Connection is a comma-separated list — proxies routinely send keep-alive, Upgrade — so it is matched token-wise rather than by substring, which would also match a header value such as no-upgrade.

Lives here rather than in @setu-ts/runtime because the kernel decides whether a request is an upgrade (after the pipeline runs) while the adapters still need the identical rule, and the kernel does not depend on the runtime package. A pure predicate is exactly what common is for (AI_GUIDELINES §2.1); @setu-ts/runtime re-exports this one rather than keeping a second copy (§11.1).

Examples

Example 1

if (isWebSocketUpgradeRequest(request.headers)) {
  // consult the upgrade router
}

Parameters

headers: Headers

The request headers

Return Type

boolean

true when the request asks for a WebSocket upgrade

Usage

import { isWebSocketUpgradeRequest } from "common/src/index.ts";