Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Send Response Headers

Just as clients send request headers to tell the server about themselves, servers send Response Headers to provide metadata about the response.

For example, if a server returns the string "hello", the client needs to know if that string is plain text, a JSON object, or a piece of HTML. The server communicates this using the Content-Type header.

Your Task

The tester will send a simple GET request. You must respond with a 200 OK status line, and include a Content-Type: text/plain header.

Remember the grammar we learned for headers: field-name ":" OWS field-value OWS CRLF

So, your response should look exactly like this:

HTTP/1.1 200 OK\r\n
Content-Type: text/plain\r\n
\r\n

Caution

Do not forget the empty \r\n line at the very end of your response! According to RFC 9112 Section 2.1, the header section must be terminated by a double CRLF. Even if you only send one header, you still need that terminating blank line.

Reference: RFC 9110 Section 8.3


Important

Run the below docker command to test your solution.

docker run \
  --rm \
  --add-host host.docker.internal:host-gateway \
  codeberg.org/level0/buildit/http-server:latest \
  --addr host.docker.internal:8080 \
  --until send_response_headers