What comes back
The server answers with the same text format, just a different first line:
HTTP/1.1 200 OK Content-Type: text/html Content-Length: 1256 <html> ...the page itself... </html>
- Status line:
VERSION CODE REASON. The status code200is the machine-readable result, andOKis the human-readable label. - Headers, again
Name: value.Content-Typesays what the body is, because the client handles each format differently:text/htmlis a web page to render,image/pngis picture bytes to display, andapplication/jsonis JSON (JavaScript Object Notation — a plain-text format for structured data that looks like{"user": "ada"}, and the standard language of APIs; lesson 4-4 covers it properly).Content-Lengthsays how many bytes the body is, so the client knows when it has everything. - Blank line, then the body: the actual page, data, or image bytes.
Everything your browser shows you arrived as the body of some response. The headers are invisible to users but they are the first thing an engineer reads when debugging: they tell you what the server thinks it sent.
Code exercise · bash
Run this. A response is stored in a variable, and the script reads its status line and extracts the code, exactly what every HTTP client library does first. head -n 1 takes the first line, cut -d' ' -f2 takes the second space-separated field.
Code exercise · bash
Your turn. Extract three things from this stored response: the status code, the Content-Type value, and the Content-Length value. grep '^Content-Type:' finds the header line, and cut -d' ' -f2 keeps the value after the space.
Quiz
A response has Content-Type: application/json. What does that tell the client?