Fixture
A recorded or hand-written response: a status, headers and body bytes, read from and written to the .http format.
The format: optional leading # ... provenance lines (ignored on read), a status line HTTP/<d>[.<d>] <three digits>[ <reason>] (the reason is ignored; HTTP/1.1 200 OK, HTTP/2 404 and HTTP/1.1 304 are all valid), Name: value header lines (the name an RFC 9110 token, the value trimmed of SP and HTAB, strict UTF-8, no NUL, no obs-fold), a blank line, and every remaining byte the body, verbatim; no blank line means an empty body. LF or CRLF ends a head line; a lone CR is refused. toBytes writes LF, HTTP/1.1, the RFC 9110 reason for the common statuses and Name: value per entry in order, so writing the parse of a canonical file reproduces it, and the body round-trips byte for byte. A consumer keeps its fixture files under its own test resources and marks them -text in its .gitattributes (a pattern over every .http file below a fixtures directory) so a checkout cannot rewrite their line endings.
Stable Core, source compatibility only. The body is copied in and read back as copies. Equality and hash are on the status, the headers and the body bytes. toString() prints the status, the header names (through HttpHeaders.toString()) and the body size, never a header value or the body. Immutable, so safe to share between threads.
Parameters
the status, in 100..599.
the response headers.
the body; copied.
Throws
if status is outside 100..599.
Properties
Functions
Writes this fixture as a mockwebserver3.MockResponse that cannot hang or corrupt the exchange. The status line is HTTP/1.1 <status> <reason> with the fixture codec's reason phrase (none for an uncommon status); every header is written as given, in order, except Content-Length and Transfer-Encoding, which the framing decides: a 204 or 205 gets no body and no Content-Length; a 304, or any response to a HEAD, gets no body and keeps the declared length (for HEAD, the body size when none was declared); a fixture carrying Transfer-Encoding is framed as chunked; every other fixture gets its body and Content-Length from the bytes. Content-Length is written after the other headers. A fixture carrying Content-Encoding: gzip must hold encoded bytes: a mismatch fails the exchange fast with an IOException, never hangs.
Builds the response a transport would return for this fixture.