interface HttpService

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

Mutable on purpose, and for the same reason ReplContext.scratch is — .header accept=x and the .get three lines later are different commands, and the whole point is that the second one remembers the first.

Properties

headers: Map<string, string>

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

Oldest first, newest last, capped at REQUESTS_KEPT.

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.

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.

Usage

import { type HttpService } from "lib/repl/http-service.ts";