Responses

Anatomy of a response

Read the status line, response headers, blank line, and optional body that a server sends back to an HTTP client.

Every HTTP response has the same broad shape as a request: a start line, headers, a blank line, then an optional body.

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 18

<h1>Hello</h1>

The status line carries the protocol version, a numeric status code, and a short reason phrase. Clients mostly care about the number. The phrase is for humans reading packet logs.

Response headers describe the payload and how to handle it. Content-Type says whether the body is HTML, JSON, or something else. Cache-Control tells caches whether they may store the response. Set-Cookie asks the client to remember state.

The empty line separates headers from the body. The body can be HTML, JSON, an image, a PDF, or empty.

Some responses intentionally have no body. 204 No Content means success with nothing to download. A response to HEAD includes headers only; the server must not send a body.

Fetch a live response and read the pieces:

curl -i https://flaviocopes.com/

You should see HTTP/2 200 (or HTTP/1.1 200 depending on negotiation), headers like content-type: text/html, then HTML starting with <!DOCTYPE html>.

Compare with headers only:

curl -I https://flaviocopes.com/rss.xml

Same status line pattern, same header block, no RSS body in the output because HEAD forbids it.

Notice that HTTP/2 in curl’s output still presents the message in this familiar layout. Under the hood the framing differs; your debugging habits can stay the same.

Check content length when debugging truncated JSON:

curl -I https://flaviocopes.com/rss.xml

Look for content-length or chunked encoding in the headers. If the downloaded size does not match, something in the middle may be cutting the stream.

Try this on your own project: call your health-check or homepage URL with curl -i and label the status line, three headers you care about, and where the body begins.

Lesson completed