IF Commons GitHub

http

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-019

Pure HTTP helpers that API clients and servers keep rewriting (commons 0001-formats FR-019): the Link header (RFC 8288) read into its links so a client follows rel="next" pages, Retry-After (RFC 9110 §10.2.3) read as a wait whether it is seconds or a date, and which methods are safe (RFC 9110 §9.2.1) so a read-only client can refuse the rest, and the entity-tag conditions of If-Match and If-None-Match (RFC 9110 §13.1) a server answers with 412 or 304. Taken from Stolos's connector SDK (src/archon/connect/sdk.ts, connector.ts), which matched rel="next" with a regular expression in two places, and erga's lib/ts/http (on @std/http/etag).

import { nextLink, retryAfterMs } from "./http.ts";
nextLink('<https://api.example.com/items?page=2>; rel="next", <https://api.example.com/items?page=9>; rel="last"');
// "https://api.example.com/items?page=2"
retryAfterMs("120", Date.now()); // 120000

Source: commons/formats/src/http.ts

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

entityTagfunction
function entityTag(token: string, weak?: boolean): string

An entity tag for content by its checksum or another stable token: strong ("token"), or weak (W/"token").

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

entityTagsfunction
function entityTags(header: string): "*" | readonly string[]

The entity tags of an If-Match or If-None-Match header, as written ("abc", W/"abc"), or *.

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

ifMatchfunction
function ifMatch(header: string | null | undefined, etag: string): boolean

Whether a request with this If-Match header may go on for content with this entity tag (RFC 9110 §13.1.1): yes where the header is absent, is *, or names the tag by strong comparison (a weak tag never matches).

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

ifNoneMatchfunction
function ifNoneMatch(header: string | null | undefined, etag: string): boolean

Whether a request with this If-None-Match header should get the content again (RFC 9110 §13.1.2), rather than 304 or 412: yes where the header is absent or names no tag equal to this one by weak comparison; no where it is *.

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

isSafeMethodfunction
function isSafeMethod(method: string): boolean

Whether a method only reads; case does not matter.

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

nextLinkfunction
function nextLink(header: string | null | undefined, rel?: string, base?: string | undefined): string | undefined

The target of the first link whose rel names rel (next by default); a rel may name several, separated by spaces.

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

parseLinkHeaderfunction
function parseLinkHeader(header: string, base?: string | undefined): readonly WebLink[]

The links of a Link header, in order; a part that is not <target>; params is skipped. Relative targets are resolved against base.

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

retryAfterMsfunction
function retryAfterMs(value: string | null | undefined, now: number): number | undefined

How long a Retry-After value asks to wait, in milliseconds from now: whole seconds, or an HTTP date (never negative); undefined where it is neither.

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

SAFE_METHODSconstno test imports it
const SAFE_METHODS: ReadonlySet<string>

The methods that only read (RFC 9110 §9.2.1).

WebLinktypeno test imports it
type WebLink = { readonly target: string; readonly params: Readonly<Record<string, string>> };

One link of a Link header: its target and its parameters (rel, type, ...), names in lower case.

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