(res: ServerResponse, status: number, message: string, method: string)
| 103 | |
| 104 | /** Send a plain-text status response (the error path for a browser or curl). */ |
| 105 | export function sendText(res: ServerResponse, status: number, message: string, method: string): void { |
| 106 | const body = Buffer.from(message.endsWith('\n') ? message : `${message}\n`, 'utf-8'); |
| 107 | res.writeHead(status, { |
| 108 | 'Content-Type': 'text/plain; charset=utf-8', |
| 109 | 'Content-Length': String(body.byteLength), |
| 110 | 'Cache-Control': 'no-store', |
| 111 | }); |
| 112 | res.end(method === 'HEAD' ? undefined : body); |
| 113 | } |
| 114 | |
| 115 | /** Send a JSON response. Used for `/api/*`, which must never get HTML back. */ |
| 116 | export function sendJson(res: ServerResponse, status: number, payload: unknown, method: string): void { |
no test coverage detected