Skip to main content

Function: guardedFetch()

guardedFetch(address, options): Promise<GuardedResponse>

Defined in: packages/agentos/src/cognition/memory/io/ingestion/guardedFetch.ts:448

Reads address, an http or https address a person gave a server, under options. Each hop resolves the host and refuses it when any of its addresses is not public (isPublicAddress) and not in allowAddresses, then connects to a checked address on a connection of its own, trying the next one when the first cannot be reached; a redirect is followed only to an address that passes the same checks, at most maxRedirects times. The answer must be a 2xx of a type in accept, and its body, decoded from gzip, deflate or br, is refused once it passes maxBytes on the wire or decoded. The whole read stops at deadlineMs.

Parameters​

address​

string

options​

GuardedFetchOptions

Returns​

Promise<GuardedResponse>

Example​

const page = await guardedFetch('https://example.com/notes', { maxBytes: 2 * 1024 * 1024, deadlineMs: 10_000 });
page.contentType; // 'text/html'

Throws​

When maxBytes or deadlineMs is not a positive number (or deadlineMs is longer than Node's longest timer), or maxRedirects is not a whole number of 0 or more, before any lookup.

Throws​

When the address, a redirect or the answer is refused, or the read fails or passes its deadline; reason says which.

Throws​

The reason of options.signal when the caller aborts it.