@prismshadow/penguin-server · packages/server/src/http/app.ts:43

Http

interface

The assembled business surface: one request in, one response (or a decline) out.

fetchAs is the same surface entered as a user already established by other means — the API socket (socket/serve.ts), whose handshake the runtime authenticated and whose owner it checked before the platform ever saw the socket. Those requests carry no cookie, so the gate in front of the routes is not the cookie one but "this user": the routes themselves, their authorization and their errors are identical.

API

@Interface()
export abstract class Http {
  abstract fetch(request: Opaque<"Request", Request>): Promise<Opaque<"Response", Response>>;
  abstract fetchAs(
      userId: string,
      request: Opaque<"Request", Request>,
    ): Promise<Opaque<"Response", Response>>;
  abstract upgrade(
      request: Opaque<"IncomingMessage", IncomingMessage>,
      socket: Opaque<"Duplex", Duplex>,
      head: Opaque<"Buffer", Buffer>,
    ): boolean;
  abstract ownOrigin(path: string): boolean;
}

Contract Topology

Static AST wiring across @Module / @Provide / @Use
@Moduleexported by
@Provideprovided by

Members (4)

fetch

fetch(request: Opaque<"Request", Request>): Promise<Opaque<"Response", Response>>
@paramrequestOpaque<"Request", Request>
@returnsPromise<Opaque<"Response", Response>>

fetchAs

fetchAs(userId: string, request: Opaque<"Request", Request>): Promise<Opaque<"Response", Response>>
@paramuserIdstring
@paramrequestOpaque<"Request", Request>
@returnsPromise<Opaque<"Response", Response>>

upgrade

upgrade(request: Opaque<"IncomingMessage", IncomingMessage>, socket: Opaque<"Duplex", Duplex>, head: Opaque<"Buffer", Buffer>): boolean

Hands a WebSocket upgrade to the contributed endpoint (HttpModule.upgrades) whose prefix covers its path most specifically — checking the handshake's Origin and session cookie first for an auth: "user" one (http/upgrade-endpoints.ts) — and answers true; false when none covers it, leaving the socket untouched. The runtime asks this per upgrade of the generation current at that moment (hmr/upgrade-seam.ts): a socket cannot cross the HTTP seam, so this is the in-process half.

@paramrequestOpaque<"IncomingMessage", IncomingMessage>
@paramsocketOpaque<"Duplex", Duplex>
@paramheadOpaque<"Buffer", Buffer>
@returnsboolean

ownOrigin

ownOrigin(path: string): boolean

Whether a write to path may reach a route group that judges its callers' origin itself (origin: "own"): what the runtime's copy of the same-origin check, in front of the seam, lets through for this generation's exact one to decide (http/own-origin.ts, app.ts).

@parampathstring
@returnsboolean