Send a Response Line
You are successfully reading incoming requests. Now it’s time to send an HTTP Response back!
An HTTP Response, much like an HTTP Request, has a strict structure defined in RFC 9112 Section 4. It begins with a Status Line (often called a Response Line).
status-line = HTTP-version SP status-code SP reason-phrase CRLF
Example: HTTP/1.1 200 OK\r\n
HTTP-version: For this course, always useHTTP/1.1.SP: A single space character.status-code: A 3-digit integer indicating the result of the request (e.g.,200).reason-phrase: A short textual description of the status code (e.g.,OK).CRLF: The carriage return and line feed (\r\n).
Your Task
Read the incoming HTTP request (wait for the \r\n\r\n boundary).
Once received, regardless of what the request asked for, you must respond with a 200 OK status line.
Because you are not sending any headers or a body yet, your response must consist of exactly the status line, followed by the empty line that terminates the header section.
Your exact response must be:
HTTP/1.1 200 OK\r\n\r\n
Warning
Notice the two
\r\nsequences at the end! The first terminates the status line. The second acts as the empty line terminating the headers block. If you only send one\r\n, the client will hang indefinitely waiting for the headers to finish!
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_line