# I’m stuck on stage (#EJ5) of build your own HTTP server; help needed! (C#)

**URL:** <https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128>\
**Category:** Challenges\
**Tags:** challenge:http-server\
**Created:** [April 15, 2024, 2:21pm UTC](https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128 "2024-04-15T14:21:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![asemarian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/asemarian/32/110_2.png) [@asemarian](https://forum.codecrafters.io/u/asemarian)\
**Post date:** [April 15, 2024, 2:21pm UTC](https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128/1 "2024-04-15T14:21:01Z")

</div>

I’m stuck on stage 6 of build your own HTTP server. I’m using C# for this challenge.

All I did was wrap a call to a method inside `Task.Run()` which would presumably allow it to run in a separate thread. The tests are failing, though. And they’re failing early, at stage #2.

Here are my logs:

```auto
remote: [stage-2] $ curl -v -X GET http://localhost:4221/
remote: [stage-2] Sending request (status line): GET / HTTP/1.1
remote: [your_program] Client accepted!
remote: [stage-2] Hint: EOF is short for 'end of file'. This usually means that your program either:
remote: [stage-2] (a) didn't send a complete response, or
remote: [stage-2] (b) closed the connection early
remote: [stage-2] Failed to connect to server, err: 'Get "http://localhost:4221/": EOF'
remote: [stage-2] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

```

This is the [line of code](https://github.com/asemarian/codecrafters-http-server-csharp/commit/90142ee97b6d03d5130c8fe1fdf6c724842935eb#diff-f91269a622f7f8e0ac4eae1ec58aefcf3bb996533a3e538fecf351416b67beceR18) (GitHub link) that has essentially changed. If I remove the `Task.Run()` all tests pass, except for stage #6 tests of course.

Anyone has any idea what’s going on here?

This is the `Main` method just for reference:

```auto
    private static void Main(string[] args)
    {
        try
        {
            using TcpListener server = new(IPAddress.Any, 4221);
            server.Start();

            while (true)
            {
                using var client = server.AcceptTcpClient();
                Console.WriteLine("Client accepted!");
                _ = Task.Run(() => HandleClient(client));
            }
        }
        catch (SocketException e)
        {
            Console.WriteLine($"SocketException: {e}");
        }
    }

```

---

<div class="post-metadata">

**Author:** ![asemarian](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/asemarian/32/110_2.png) [@asemarian](https://forum.codecrafters.io/u/asemarian)\
**Post date:** [April 16, 2024, 1:13pm UTC](https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128/2 "2024-04-16T13:13:48Z")

</div>

I managed to fix the problem and pass stage #6. The main issue was with the way I was parsing headers. Somehow, the regex also matched when there were no headers present.

---

<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 21, 2024, 1:14pm UTC](https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128/3 "2024-04-21T13:14:39Z")

</div>

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:49am UTC](https://forum.codecrafters.io/t/i-m-stuck-on-stage-ej5-of-build-your-own-http-server-help-needed-c/128/4 "2024-06-04T05:49:10Z")

</div>

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