gitoria
All repositories: gitoria
1.0 KB
// hl:http1 — HTTP response wrapper (file-as-class: Response)// Split from the former multi-class server.hl (mission 027).// The file root IS the constructor (mission 052 — `__construct` is gone).// Construction is positional: `new Response(body)` or// `new Response(body, { status = 404 })`. Positional args bind to properties in// DECLARATION order, so `body` and `options` must stay the first two// declarations; the run body below folds `options` into status/headers.// A Bytes body is sent raw, byte for byte (ticket #88) — what an app stored from// `req.bytes` can be served back — and says application/octet-stream unless the// headers name a type.String | Bytes body = ''Hybrid options = nullNumber status = 200Hybrid headers = {}if (options != null) {if (options.status != null) {status = options.status}if (options.headers != null) {headers = options.headers}}if (hlTypeName(body) == 'Bytes') {let typed = falsefor (k of headers.keys()) {if (k.toLowerCase() == 'content-type') { typed = true }}if (!typed) { headers['Content-Type'] = 'application/octet-stream' }}
Branches
- mainmain branch