IF Commons GitHub

physical/http-server

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-netboot-physical FR-004

The HTTP server of the boot machine, on node:http. Firmware and GRUB are picky clients: GRUB's HTTP client compares Content-Length: case-sensitively and reads every file as empty if the name is in lower case, and sends HEAD and then GET on one connection. So the header names are written in their canonical case, connections are kept alive, and a file is streamed (an installer image is several GB) with Range for a resumed download. The handler is a function of a plain request to a plain response.

import { httpServer } from "./http-server.ts";
// const s = await httpServer({ port: 0, handle: async () => ({ status: 200, headers: {}, body: "ok" }) }); await s.stop();

Source: commons/netboot/src/physical/http-server.ts

2 of 14 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

physical.BootRequesttypeno test imports it
type BootRequest = { readonly method: string; readonly path: string; readonly host: string; readonly from: string; readonly range: string | undefined; readonly body: Uint8Array };

A request, as the handler sees it.

physical.BootBodytypeno test imports it
type BootBody = string | Uint8Array | { readonly file: string; readonly size: number };

What a response carries: text or bytes, or a file to stream.

physical.BootResponsetypeno test imports it
type BootResponse = { readonly status: number; readonly headers: Readonly<Record<string, string>>; readonly body: BootBody };

A response.

physical.HttpOptionstypeno test imports it
type HttpOptions = { readonly port: number; readonly hostname?: string; readonly handle: (r: BootRequest) => Promise<BootResponse> };

What the server is given.

physical.HttpServertypeno test imports it
type HttpServer = { readonly port: number; stop(): Promise<void> };

A running server.

physical.parseRangefunctionno test imports it
function parseRange(header: string | undefined, size: number): "none" | "unsatisfiable" | { readonly start: number; readonly end: number; }

The byte range a Range: bytes=a-b asks of a file of size bytes, or why it cannot be given.

physical.httpServerfunctionno test imports it
function httpServer(o: HttpOptions): Promise<HttpServer>

Starts the server.

BootRequesttypeno test imports it
type BootRequest = { readonly method: string; readonly path: string; readonly host: string; readonly from: string; readonly range: string | undefined; readonly body: Uint8Array };

A request, as the handler sees it.

BootBodytypeno test imports it
type BootBody = string | Uint8Array | { readonly file: string; readonly size: number };

What a response carries: text or bytes, or a file to stream.

BootResponsetypeno test imports it
type BootResponse = { readonly status: number; readonly headers: Readonly<Record<string, string>>; readonly body: BootBody };

A response.

HttpOptionstypeno test imports it
type HttpOptions = { readonly port: number; readonly hostname?: string; readonly handle: (r: BootRequest) => Promise<BootResponse> };

What the server is given.

HttpServertypeno test imports it
type HttpServer = { readonly port: number; stop(): Promise<void> };

A running server.

parseRangefunction
function parseRange(header: string | undefined, size: number): "none" | "unsatisfiable" | { readonly start: number; readonly end: number; }

The byte range a Range: bytes=a-b asks of a file of size bytes, or why it cannot be given.

Imported by 18 tests of the run (18 passed, 0 failed): the library's results

httpServerfunction
function httpServer(o: HttpOptions): Promise<HttpServer>

Starts the server.

Imported by 18 tests of the run (18 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.