src/http.ts
15 lines and 2 functions in DrDustinEdwards/capsid, at commit daa875b on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| textResponse | 11 to 13 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
| jsonResponse | 16 to 18 | 1 | 100% | OkCRAP 1 | No data: mutation testing has not run on this repo yet |
Imports
It imports no other module of this repo. Imported by src/access-sync.ts, src/bench.ts, src/dcr.ts, src/ops-feed.ts, src/ops-hooks.ts, src/ops-otlp.ts, src/ops-session-auth.ts, src/portal-actions.ts, src/portal-app.ts, src/portal-claims.ts, src/portal-library.ts, src/portal-overnight.ts, src/portal-packages.ts, src/push.ts, src/routes.ts, src/shadow.ts.
Source
/**
* The plain responses Capsid answers with: text and JSON, never cached. One copy, so a header
* added here reaches every answer. A response with its own caching (public-data.ts) or its own
* content type builds its own Response.
*/
const TEXT = "text/plain;charset=utf-8";
const JSON_TYPE = "application/json";
/** A plain-text answer, never cached. `extra` adds or overrides headers. */
export function textResponse(message: string, status: number, extra: Record<string, string> = {}): Response {
return new Response(message, { status, headers: { "Content-Type": TEXT, "Cache-Control": "no-store", ...extra } });
}
/** A JSON answer, never cached. `extra` adds or overrides headers. */
export function jsonResponse(body: unknown, status = 200, extra: Record<string, string> = {}): Response {
return new Response(JSON.stringify(body), { status, headers: { "Content-Type": JSON_TYPE, "Cache-Control": "no-store", ...extra } });
}