Home / Docs / Specification / 31. HTTP servers
31.5 Writing a reply
Release v0.4.0
- Checks. Before any byte is written, a reply MUST have a status from 200 to 599; no body on a
204or a304; header names that are tokens, in any case; header values with no CR, LF, NUL or other control character but tab, and no 0x7F; none ofConnection,Content-Length,Date,Keep-Alive,Proxy-Connection,TE,Trailer,Transfer-EncodingandUpgrade, in any letter case; at most 100 headers, and at most 64 KiB of them, each counted asname: valuewith its CRLF. Otherwisereplyfails withBadReply, nothing is sent, and the reply right stays held. - The bytes.
HTTP/1.1 <status> <reason>, with the reason phrase of RFC 9110 §15 (and of RFC 6585 for429and431), or an empty one for any other status; thenDateas an IMF-fixdate;Content-Lengthwith the length of the body given, except on a204or a304; the program's headers, in order, as given;content-type: text/plain; charset=utf-8when the reply names no content type and carries a body;Connection: closewhen the connection closes after the reply; the empty line; and the body, unless the request wasHEADor the status is204or304. AHEADreply keeps theContent-Lengthof the body given and gets no default content type. - The host's own answers (refusals,
421,503,500) have an empty body,Content-Length: 0,Retry-After: 1where ADR 0123 rule 14 asks for it, andConnection: closewhen the connection closes, as it does after every refusal of §3 and §4.100 Continueis the status line and the empty line alone. - Cost. Checking and writing a reply of r bytes is O(r), into one buffer reserved once.