Docs / Controlled responses for testing clients

Controlled responses for testing clients

Client code is usually written against a server that behaves. Retries, timeouts and error handling get exercised for the first time in production, when a real service returns a 503 with a Retry-After header, answers slowly, sends a truncated gzip stream or declares one content type and delivers another. By then the question is no longer how the client should behave but why it behaved as it did.

This group makes those situations reproducible. Any status from 200 to 599 can be requested, with an optional Retry-After value, and the body says the status was requested on purpose so that nobody mistakes it for an outage. A response can be delayed by up to ten seconds, which is enough to trigger most client timeouts. A body of an exact number of bytes, up to the service's one megabyte cap, tests size limits and streaming. And a set of broken responses covers the failures that crash parsers: invalid gzip, gzip cut short, bytes that are not valid UTF-8, JSON that does not parse, and a body that contradicts its declared type.

These endpoints are rate-limited more tightly than the rest, because a retry loop pointed at a deliberate 503 will otherwise keep going. That limit is itself something to test: it answers with a real 429 and a Retry-After header, the same way every limit on this service does.

Nothing here is cached, and none of these responses ever reflects a real problem with the service.

Every endpoint in this group

/status/{code}?[retry_after=]

Respond with the given HTTP status (200-599), with an explanatory body

code: status 200-599; retry_after (optional): seconds for a Retry-After header (429, 503)

curl "https://agent-helper.org/status/503?retry_after=30"

/delay/{seconds}

Respond after a delay of up to 10 seconds

seconds: 0-10, decimals allowed

curl "https://agent-helper.org/delay/2.5"

/size/{bytes}

Body of exactly N bytes (up to the 1 MB response cap), streamed with Content-Length

bytes: 0-1048576

curl "https://agent-helper.org/size/1048576"

/broken/{kind}

Deliberately malformed responses: bad gzip, truncated gzip, invalid UTF-8, invalid JSON, wrong type

kind: one of gzip, gzip-truncated, charset, json, content-type

curl "https://agent-helper.org/broken/gzip"