With headers parsed, the reader sits at the body - and Content-Length tells you exactly how many bytes it is. Today you read precisely that many bytes, no more and no less.
Read the response body as exactly the number of bytes given by Content-Length.
The most common way a response frames its body is Content-Length: a header
stating the exact byte count that follows the blank line. The reader is already
sitting at the first body byte, so reading the body is just reading exactly that
many bytes - Content-Length: 5 means read five, giving hello. Read fewer and
you truncate the body; read more and you steal bytes from whatever comes next on the
connection, which matters the moment a connection carries more than one response.
Pin the empty body: Content-Length: 0 is legitimate and common - a redirect, a
204, a HEAD response - and it means read zero bytes, leaving the reader untouched.
Reading exactly the declared count, even when that count is zero, is what keeps the
stream aligned for the keep-alive work in chapter four.
// read the Content-Length header, parse it as an int N, then// read EXACTLY N bytes from the reader as the body. N may be 0.func (r *reader) readN(n int) ([]byte, error) {// read n bytes and return them}