function request
request(asked: { verb: string; url: string; headers: ReadonlyMap<string, string>; body?: string | null; timeoutMs?: number; maxBytes?: number; }): Promise<HttpRequest>

Sends one request and records everything about it, including the ways it can go wrong.

Nothing here throws. A REPL command that throws is a stack trace where a sentence belongs, and every failure this can meet — refused, unresolved, timed out, aborted — is an answer worth printing rather than an exception worth raising.

The body is read through the stream rather than with .text() so that BODY_LIMIT_BYTES can be enforced BEFORE the bytes are in memory: a REPL pointed at an endless stream should stop reading it, not fill the heap and then apologise. A body that is not text is counted and not decoded, because the one thing worse than a huge response is a terminal full of PNG.

import { request } from './http-service.ts';

// Defined, not invoked: it opens a socket.
function example() {
  return request({ verb: 'GET', url: 'http://localhost:1/x', headers: new Map() });
}

Parameters

asked: { verb: string; url: string; headers: ReadonlyMap<string, string>; body?: string | null; timeoutMs?: number; maxBytes?: number; }

Return Type

Promise<HttpRequest>

Usage

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