A POST Echo Keeps the Bytes
A POST request carries its body after the empty line with Content-Length and a Content-Type; the scripted server echoes the body byte for byte.
The question
A POST request sends content to the server. In the recording of this book (curl 8.5.0, the scripted server lmmock 0.1.0, loopback, 2026-11-21) the route /echo answers with the bytes it received. Where does the content sit in the request, which fields describe it, and how can the two bodies, the one sent and the one echoed, be compared byte for byte?
Work it by hand
RFC 9110, section 9.3.3, says that POST asks the target resource to process the representation enclosed in the request; section 8.3 says that the Content-Type field gives the media type of that content. RFC 9112, section 6.3, item 6, says that the Content-Length value is the body length in bytes.
Take a constructed pair that no case uses. The request is POST /echo HTTP/1.1, some fields including Content-Length: 2, the empty line, and the bytes 68 69 (hi). The response echoes 68 69. The request body has 2 bytes, the response body has 2 bytes, and they are the same bytes.
Run it
The demo reads the two recorded POSTs and their echoes, connections 5 and 6.

Watch the steps (recorded video)
let lines = str_split(segments, "\n");
let rows = str_list(); let same = 0;
if (lines.len() < 2) { out.fail("a request and a response are needed"); }
for (k in range(0, lines.len() / 2)) {
let sent = ssl.unhex(str_split(lines.at(2 * k), "|").at(2));
let got = ssl.unhex(str_split(lines.at(2 * k + 1), "|").at(2));
let ty = str_find(sent, "Content-Type: ");
let rest = str_substr(sent, ty + 14, str_len(sent) - ty - 14);
let at = str_find(sent, "Content-Length: ");
if (ty < 0 || at < 0) { out.fail("the request needs both fields"); }
let more = str_substr(sent, at + 16, str_len(sent) - at - 16);
let n = str_to_int(str_split(more, "\r\n").at(0));
let first = "length";
if (ty < at) { first = "type"; }
let tail_in = str_substr(sent, str_len(sent) - n, n);
if (tail_in == str_substr(got, str_len(got) - n, n)) { same = same + 1; }
rows.add(str(k + 1) + "|" + str_split(rest, "\r\n").at(0) + "|" + first);
}
let answer = same;
lmcode_return_put("rows", rows);
{
"answer": 2,
"rows": [
"1|text/plain|type",
"2|application/x-www-form-urlencoded|length"
]
}It takes the segments two at a time, a request and its response. Lines 7 and 8 read the Content-Type value, and lines 9 to 12 the Content-Length value. Line 16 compares the last bytes of both messages, as many as the field says.
Line 17 puts the Content-Type value and the field that came first into the table; rows 1 and 2 are connections 5 and 6, and a cell is cut after 24 characters. The answer on line 19 is the number of echoes that kept the body: 2.
In the recording the first request set Content-Type: text/plain and its field comes before Content-Length: 5; the second request, sent without that option, carries Content-Length: 5 first and then Content-Type: application/x-www-form-urlencoded. The order is the client's choice: do not rely on it.
You can change segments. With fewer than two lines the run stops with "a request and a response are needed", and a request with no Content-Type or no Content-Length stops it with "the request needs both fields" (measured). An odd last line is ignored. The program trusts the Content-Length value: a field larger than the real body makes it compare bytes of the head too (measured: a field of 9 on a 5-byte body still counted as kept).
Your turn
The program below should report the body length of a request and of its response, and whether the two bodies are the same bytes. Several candidate programs are offered. Read them, run them on pairs of messages of your own, and decide which of them is right for every pair. Every message in the cases is constructed; the picture says so.

fn body(msg: string) -> string {
let cut = str_find(msg, "\r\n\r\n") + 4;
return str_substr(msg, cut, str_len(msg) - cut);
}
let sent = body(ssl.unhex(request));
let got = body(ssl.unhex(response));
let same = 0;
if (ssl.unhex(request) == ssl.unhex(response)) { same = 1; }
let answer = int_list();
answer.add(str_len(sent)); answer.add(str_len(got)); answer.add(same);
{
"answer": [
8,
8,
0
]
}Return [request body length, response body length, same] as a list of three integers, where same is 1 if the two bodies are the same bytes and 0 if they are not. The hex inputs request and response are a POST request and the response to it; each message is a head, the empty line and the body, and every line of the head ends with 0d 0a. Lengths are counted in bytes, after the empty line. Check runs your program on this pair and on five others.
Read the result carefully
The echo shows that this script returns the bytes it receives. It does not show that a server understands a media type: the script ignores Content-Type, and the request with the form type and the one with text/plain got the same kind of answer. A real service that processes a form would parse it; this recording does not show that.
The cases are made of the bytes curl sends but are not a capture. A body that is not text, a chunked body or a body larger than the input limit is outside this lesson. For constructed POST messages with form fields, see POST Body Carries Form Fields and JSON Body Names Fields.
Recap
- A POST body follows the empty line; Content-Length gives its size in bytes.
- Content-Type names the media type; the order of the fields is not fixed.
- This server echoes the request body, so the two bodies are equal in the recording.
- The body of a message is the bytes after its empty line.