

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Server
incomplete
2: Content Length
incomplete
3: Response
incomplete
4: Other Common Headers
incomplete
5: Handler
incomplete
6: Code Review
incomplete
7: Refactor
incomplete
This lesson's interactive features are locked, please to keep using them
While there isn't an official list of all the headers that should be in most responses, there are a few that are common enough that we should include them. Namely:
Content-Length (The size of the response body)Connection (Whether the connection should be kept alive or closed)Content-Type (The MIME type of the response body)So, let's build some more of the pieces we'll need to send valid dynamic responses. Remember that HTTP responses follow the same HTTP message format:
HTTP-message = start-line CRLF
*( field-line CRLF )
CRLF
[ message-body ]
The only difference is that the start-line is a status-line instead of a request-line. From RFC 9112:
status-line = HTTP-version SP status-code SP [ reason-phrase ]
For example:
HTTP/1.1 200 OK
Or perhaps:
HTTP/1.1 404 Not Found
Some interesting tidbits about the reason-phrase, from Section 4,
A client SHOULD ignore the reason-phrase content because it is not a reliable channel for information (it might be translated for a given locale, overwritten by intermediaries, or discarded when the message is forwarded via other versions of HTTP). A server MUST send the space that separates the status-code from the reason-phrase even when the reason-phrase is absent (i.e., the status-line would end with the space).
So, while reason phrases are typically included (and match one to one with the status code), they are not required and should be ignored by clients. Kinda funny.
200400500200 should return HTTP/1.1 200 OK400 should return HTTP/1.1 400 Bad Request500 should return HTTP/1.1 500 Internal Server ErrorContent-Length (Set to the given size)Connection (Set to close because we're not doing keep-alive's yet)Content-Type (Set to text/plain)HTTP/1.1 200 OK
Content-Length: 0
Connection: close
Content-Type: text/plain
To keep things simple for this course, we'll only use the mimetype, e.g. text/plain in the Content-Type header. Don't add a charset or you'll fail the exact-match tests.
Run and submit the CLI tests with your server running.