Functions

f
create(): HttpService

An empty store — one per session.

f
formatBytes(bytes: number): string

A byte count as a person would read it: 0 bytes, 812 bytes, 4.2 KB, 1.3 MB.

f
isTextual(contentType: string): boolean

Whether a content type is something a terminal should be asked to print.

f
isValidHeaderName(name: string): boolean

Whether a name is one HTTP will carry — the token characters RFC 9110 allows, and no others.

f
parseHeader(text: string): { name: string; value: string; } | null

A header as it was typed, or null where that is not a header at all.

f
parseRequestKind(target: string): RequestReference

Which request an argument names: a name (#3), a position counted back (2), or a URL.

f
peekRequest(
httpService: HttpService,
verb: string | null,
url: string,
pageUrl?: string | null
): HttpRequest | null

The most recent request a [verb:]url means, or null where the session never made one.

f
resolveUserInputURL(
target: string,
pageUrl: string | null
): string | null

The absolute URL a target means, or null where it means nothing usable.

f
setQueryParams(
url: string,
params: Readonly<Record<string, unknown>>
): string

url, with params folded into its query: { page: 2 } on /api/users is /api/users?page=2.

f
setUserAgent(
httpService: HttpService,
session: { toJSON(expression: string): Promise<string | null>; }
): Promise<void>

Replaces the default user-agent with the page's own, which is the one a server should see.

f
store(
httpService: HttpService,
request: HttpRequest
): void

Files a request, newest last, naming it as it goes and dropping the oldest once there are REQUESTS_KEPT of them.

Interfaces

I
HttpRequest

One request and whatever became of it.

  • at: number

    When it was made, for ordering and for saying how long ago.

  • failed: string | null

    Why there is no reply, said the way it would be said out loud. null where there is one.

  • id: number

    What this request is called for the rest of the session: #3, and .request #3 afterwards.

  • ms: number

    Wall-clock milliseconds, rounded — a REPL has no use for the fractions.

  • request: Request

    The request, exactly as it was made.

  • response: Response | null

    null where it failed before a reply — DNS, connection refused, timeout.

I
HttpService

A session's HTTP state: the headers it will send next, and everything it has sent.

  • headers: Map<string, string>

    Saved for every upcoming request, lower-cased. .header list prints this.

  • lastId: number

    The last id handed out. Kept here rather than counted from requests.length, which stops being the number of requests made the moment the cap drops the oldest one — and an id that starts repeating is worse than no id at all.

  • requests: HttpRequest[]

    Oldest first, newest last, capped at REQUESTS_KEPT.

  • scratchpadText: string

    The body buffer .post … : opens: one for the life of the session, so reopening it continues the same thought rather than starting a blank one — the request equivalent of the scratchpad a prompt keeps. Saved empty is how it is cleared.

I
Request

What was actually handed to fetch — the request, as this session made it.

I
Response

What came back. Absent on an HttpRequest that never got a reply.

Type Aliases

Variables

v
DEFAULT_HEADERS: ReadonlyMap<string, string>

What a session sends before you have said anything about headers.

v
REQUESTS_KEPT: 200

How many requests a session keeps.