entityTagfunctionfunction entityTag(token: string, weak?: boolean): stringAn entity tag for content by its checksum or another stable token: strong ("token"), or weak (W/"token").
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()); // 120000entityTagfunctionfunction entityTag(token: string, weak?: boolean): stringAn entity tag for content by its checksum or another stable token: strong ("token"), or weak (W/"token").
entityTagsfunctionfunction entityTags(header: string): "*" | readonly string[]The entity tags of an If-Match or If-None-Match header, as written ("abc", W/"abc"), or *.
ifMatchfunctionfunction ifMatch(header: string | null | undefined, etag: string): booleanWhether 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).
ifNoneMatchfunctionfunction ifNoneMatch(header: string | null | undefined, etag: string): booleanWhether 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 *.
isSafeMethodfunctionfunction isSafeMethod(method: string): booleanWhether a method only reads; case does not matter.
nextLinkfunctionfunction nextLink(header: string | null | undefined, rel?: string, base?: string | undefined): string | undefinedThe target of the first link whose rel names rel (next by default); a rel may name several, separated by spaces.
parseLinkHeaderfunctionfunction 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.
retryAfterMsfunctionfunction retryAfterMs(value: string | null | undefined, now: number): number | undefinedHow 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.
SAFE_METHODSconstno test imports itconst SAFE_METHODS: ReadonlySet<string>The methods that only read (RFC 9110 §9.2.1).
WebLinktypeno test imports ittype 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.