Framing Gives the Body Length
A response body is as long as Content-Length says, except that a response to HEAD, and one with status 1xx, 204 or 304, has no body.
The question
After the empty line, how many bytes belong to the response? The recording of this book (curl 8.5.0 and the scripted server lmmock 0.1.0, loopback only, made on 2026-11-21) has two answers to nearly the same question. The request GET /hello got a body of 5 bytes. The request HEAD /hello got a response with the same fields and no body at all. What decides, and which number does the receiver trust?
Work it by hand
RFC 9112, section 6.3, lists how the length of a message body is found, in order of precedence. Item 1: any response to a HEAD request, and any response with a status code 1xx, 204 or 304, ends at the first empty line, whatever its fields say. Item 6: otherwise, if a valid Content-Length field is present, its decimal value is the body length in bytes.
Apply it to a constructed response to a GET: HTTP/1.1 200 OK, the field Content-Length: 4, the empty line, and the bytes ping. Not item 1, so read the field: 4 bytes. Four bytes follow the empty line, and they match. Now the same response to a HEAD: item 1 comes first, so the body is 0 bytes, although the field still says 4.
Run it
The demo reads the two recorded responses side by side.

Watch the steps (recorded video)
let both = str_list(); both.add(get_response); both.add(head_response);
let methods = "GET HEAD"; let rows = str_list(); let got = int_list();
for (k in range(0, 2)) {
let text = ssl.unhex(both.at(k));
let cut = str_find(text, "\r\n\r\n");
if (cut < 0) { out.fail("no empty line in the message"); }
let at = str_find(text, "Content-Length: ");
if (at < 0) { out.fail("no Content-Length field"); }
let value = str_substr(text, at + 16, cut + 2 - at - 16);
let said = str_to_int(str_split(value, "\r\n").at(0));
let present = str_len(text) - cut - 4;
got.add(present);
let name = str_split(methods, " ").at(k);
let size = str(str_len(text));
rows.add(name + "|" + str(said) + "|" + str(present) + "|" + size);
}
let answer = "bodies of " + str(got.at(0)) + " and " + str(got.at(1));
lmcode_return_put("rows", rows);
{
"answer": "bodies of 5 and 0",
"rows": [
"GET|5|5|106",
"HEAD|5|0|101"
]
}Lines 4 and 5 decode a response and find its empty line. Lines 7 to 10 find the field and read its number. Line 11 counts the bytes that are really present after the empty line, and lines 13 to 15 make one row of the table. The GET response is 106 bytes long with a field of 5 and 5 body bytes; the HEAD response is 101 bytes with the same field and 0 body bytes.
RFC 9110, section 9.3.2, says that HEAD is identical to GET except that the server MUST NOT send content. That is what the recording shows. The table shows what is present; the rule says what the receiver should read, and for HEAD those two happen to agree.
You can change the two inputs. A message without an empty line, or without the text Content-Length, stops the run with "no empty line in the message" or "no Content-Length field"; the name is matched as written, so content-length in lower case stops it too (measured). Field names are case-insensitive in RFC 9110, section 5.1; this program is stricter. A value that is not a number is read as 0.
Your turn
The program below should say how many body bytes a recipient should read after the empty line. Several candidate programs are offered. Read them, run them on responses of your own, and decide which of them is right for every response. Some responses in the cases are recorded and some are constructed, and the picture of each says which.

let text = ssl.unhex(response);
let head = str_substr(text, 0, str_find(text, "\r\n\r\n") + 2);
let code = str_substr(text, 9, 3);
let answer = 0;
let at = str_find(head, "Content-Length: ");
if (at >= 0) {
let rest = str_substr(head, at + 16, str_len(head) - at - 16);
answer = str_to_int(str_split(rest, "\r\n").at(0));
}
lmcode_return_put("status", str_to_int(code));
{
"answer": 12,
"status": 200
}Return the number of body bytes that the recipient of the response in the hex input response should read after the empty line, as an integer, for a message sent in answer to the request method in the text request_method (GET, HEAD or POST). Use RFC 9112's order: a response to HEAD and a response with a status code 1xx, 204 or 304 has no body; otherwise the body is as long as the Content-Length field says. Every response here has a Content-Length field, written Content-Length, unless it is one of those with no body. The message may hold fewer or more bytes than the field says. Check runs your program on this input and on nine others.
Read the result carefully
The table counts bytes that were present in a recording; the exercise returns how many a recipient should expect. They differ whenever the message was cut short or other bytes follow it, and RFC 9112, section 6.3, item 6, says a recipient MUST consider a message incomplete if fewer arrive than the field says. A recording shows what happened once, not what a receiver must do.
This recording has no chunked response, because the scripted server sends none: Transfer-Encoding comes before Content-Length in the same list, and stated here, not run, a chunked body is read another way. See Content-Length Counts the Body and Chunked Transfer Ends With Zero.
Recap
- A response to HEAD, and a response with status 1xx, 204 or 304, has no body whatever its fields say.
- Otherwise a valid Content-Length gives the body length in bytes.
- A HEAD response can carry the same Content-Length as the GET and still end at the empty line.
- Bytes present are what arrived; the field is what the sender announced.