# I keep getting timeout on the last test for stage (#CN2) for the HTTP challenge

**URL:** <https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159>\
**Category:** Challenges\
**Tags:** challenge:http-server\
**Created:** [April 20, 2024, 6:30am UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159 "2024-04-20T06:30:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dodumosu](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/dodumosu/32/141_2.png) [@dodumosu](https://forum.codecrafters.io/u/dodumosu)\
**Post date:** [April 20, 2024, 6:30am UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159/1 "2024-04-20T06:30:10Z")

</div>

I’m stuck on stage 4. I’m not sure what I’m doing wrong, and I’m basically flailing at this point.

Here are my logs:

```auto
remote: Running tests on your code. Logs should appear shortly...
remote:
remote: [stage-1] Running tests for Stage #1: Bind to a port
remote: [stage-1] $ ./your_server.sh
remote: [stage-1] Connecting to localhost:4221 using TCP
remote: [your_program] Logs from your program will appear here!
remote: [stage-1] Success! Closing connection
remote: [stage-1] Test passed.
remote:
remote: [stage-2] Running tests for Stage #2: Respond with 200
remote: [stage-2] $ ./your_server.sh
remote: [stage-2] You can use the following curl command to test this locally
remote: [stage-2] $ curl -v -X GET http://localhost:4221/
remote: [stage-2] Sending request (status line): GET / HTTP/1.1
remote: [your_program] Logs from your program will appear here!
remote: [your_program] Connected by ('127.0.0.1', 52418)
remote: [stage-2] Test passed.
remote:
remote: [stage-3] Running tests for Stage #3: Respond with 404
remote: [stage-3] $ ./your_server.sh
remote: [stage-3] You can use the following curl command to test this locally
remote: [stage-3] $ curl -v -X GET http://localhost:4221/vanilla/dooby-humpty
remote: [stage-3] Sending request (status line): GET /vanilla/dooby-humpty HTTP/1.1
remote: [your_program] Logs from your program will appear here!
remote: [your_program] Connected by ('127.0.0.1', 52514)
remote: [stage-3] Test passed.
remote:
remote: [stage-4] Running tests for Stage #4: Respond with content
remote: [stage-4] $ ./your_server.sh
remote: [stage-4] You can use the following curl command to test this locally
remote: [stage-4] $ curl -v -X GET http://localhost:4221/echo/Horsey/humpty-scooby
remote: [stage-4] Sending request (status line): GET /echo/Horsey/humpty-scooby HTTP/1.1
remote: [your_program] Logs from your program will appear here!
remote: [your_program] Connected by ('127.0.0.1', 52610)
remote: [stage-4] Failed to dump response: 'context deadline exceeded (Client.Timeout or context cancellation while reading body)'
remote: [stage-4] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

And here’s a snippet of my code:

```python

# Uncomment this to pass the first stage
import socket

def main():
    # You can use print statements as follows for debugging, they'll be visible when running tests.
    print("Logs from your program will appear here!")

    # Uncomment this to pass the first stage
    #
    server_socket = socket.create_server(("localhost", 4221), reuse_port=True)
    with server_socket:
        conn, addr = server_socket.accept() # wait for client
        with conn:
            print(f'Connected by {addr}')
            while True:
                response = 'HTTP/1.1 404 Not Found\r\n\r\n'

                request_content = conn.recv(4096).decode()
                lines = request_content.split('\r\n')

                line = lines[0]
                if line.startswith('GET'):
                    _, path, _ = line.split(' ')
                    if path == '/':
                        response = 'HTTP/1.1 200 OK\r\n\r\n'
                    elif path.startswith('/echo'):
                        subpath = path[6:]
                        computed_length = len(subpath)
                        response = 'HTTP/1.1 200 OK\r\n\r\n'
                        response += 'Content-Type text/plain\r\n\r\n'
                        response += f'Content-Length: {computed_length}\r\n\r\n'
                        response += f'{subpath}\r\n\r\n'

                conn.sendall(response.encode())

if __name__ == " __main__":
    main()

```

---

<div class="post-metadata">

**Author:** ![dodumosu](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/dodumosu/32/141_2.png) [@dodumosu](https://forum.codecrafters.io/u/dodumosu)\
**Post date:** [April 20, 2024, 2:58pm UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159/2 "2024-04-20T14:58:35Z")

</div>

i finally somehow saw the missing colon after the `Content-Type` header

---

<div class="post-metadata">

**Author:** ![rohitpaulk](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/rohitpaulk/32/6_2.png) [@rohitpaulk](https://forum.codecrafters.io/u/rohitpaulk)\
**Post date:** [April 21, 2024, 1:06am UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159/3 "2024-04-21T01:06:40Z")

</div>

Ah, nice find @dodumosu. I know the errors here can be cryptic, we’re going to work on improving them. More on this here:

> [@Stage #AP6 file not found context deadline exceeded](https://forum.codecrafters.io/t/stage-7-file-not-found-context-deadline-exceeded/50/5):
>
> Sorry for the delay in responding here folks! We do know that the logs for the HTTP challenge can be a bit cryptic. This is because we’re using an off-the-shelf HTTP client which doesn’t emit friendly error messages where there’s a protocol-level error (like a missing colon, or inverted CRLF etc.). We’re going to fix this by shipping our own parser with friendly errors soon (we did this for Redis recently and it was super helpful).

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 26, 2024, 1:06am UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159/4 "2024-04-26T01:06:49Z")

</div>

Closed on April 26, 2024, 1:06am UTC

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [June 4, 2024, 5:45am UTC](https://forum.codecrafters.io/t/i-keep-getting-timeout-on-the-last-test-for-stage-cn2-for-the-http-challenge/159/5 "2024-06-04T05:45:15Z")

</div>

Note: I’ve updated the title of this post to include the stage ID (#CN2). You can learn about the stages rename here: [Upcoming change: Stages overhaul](https://forum.codecrafters.io/t/upcoming-change-stages-overhaul/375)
