The header block, assembled with String.join
The header block, assembled with String.join
Answer
String header = String.join("\r\n", "HTTP/1.1 200 OK", "Content-Type: " + mediaType + "; charset=" + charset.name(), "Content-Length: " + page.length, "Connection: close", "", ""); byte[] head = header.getBytes(StandardCharsets.US_ASCII);
`String.join` inserts the separator *between* elements, so the two empty elements at the end buy you two more CRLFs: one closes the last header, one closes the block. `page.length` is the byte count of the array you are about to concatenate, not the character count of any `String`, so the announced length is true by construction — and the header encodes as US-ASCII because a header is protocol, never platform text.
Harold 4e ch9 §A Single-File Server