method MockResponse.prototype.snapshot
Since 0.1.0
MockResponse.prototype.snapshot(): ResponseSnapshot

Returns a snapshot of the current response state (status, headers, body). Enables middleware to inspect the response after next() returns — required for transparent response caching.

The returned object is a READ view, not a defensive copy: headers is the live Headers instance backing the response. Treat it as read-only — mutating it mutates the response. (No copy is taken deliberately: cloning a Headers collapses repeated Set-Cookie values into one comma-joined header, which would corrupt multi-cookie responses.)

Returns a discriminated union keyed on streaming: when false, body is Uint8Array | string | null (buffered); when true, body is a ReadableStream<Uint8Array> (live stream). Middleware that reads the body (e.g. cache middleware) must check streaming first to avoid draining a live stream.

Return Type

ResponseSnapshot

The status code, headers, and either a buffered body or a live stream

Usage

import { MockResponse } from "testing/src/index.ts";