TLDR Web Dev · ARTICLES & TUTORIALS
HOW DO HTTP SERVERS FIGURE OUT CONTENT-LENGTH?
Summary from the TLDR Web Dev newsletter
HTTP servers determine the "Content-Length" header, which indicates the size of the response body in two ways. When the response is small enough to fit in a server buffer, the length is calculated and sent directly. For larger responses, HTTP employs "chunked transfer encoding", dividing the data into chunks with their respective lengths.