{"id":28470844,"url":"https://github.com/hdbr00/cf-http-server-csharp","last_synced_at":"2025-07-01T20:32:48.557Z","repository":{"id":296096156,"uuid":"965354297","full_name":"hdbr00/CF-Http-server-csharp","owner":"hdbr00","description":"HTTP server from scratch, using C#","archived":false,"fork":false,"pushed_at":"2025-06-02T02:34:23.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-07T10:06:36.418Z","etag":null,"topics":["csharp-code","http-server"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hdbr00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-13T01:11:09.000Z","updated_at":"2025-06-02T02:34:26.000Z","dependencies_parsed_at":"2025-05-29T17:01:47.861Z","dependency_job_id":null,"html_url":"https://github.com/hdbr00/CF-Http-server-csharp","commit_stats":null,"previous_names":["hdbr00/cf-http-server-csharp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hdbr00/CF-Http-server-csharp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hdbr00%2FCF-Http-server-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hdbr00%2FCF-Http-server-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hdbr00%2FCF-Http-server-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hdbr00%2FCF-Http-server-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hdbr00","download_url":"https://codeload.github.com/hdbr00/CF-Http-server-csharp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hdbr00%2FCF-Http-server-csharp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263033188,"owners_count":23403113,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp-code","http-server"],"created_at":"2025-06-07T10:06:40.609Z","updated_at":"2025-07-01T20:32:48.462Z","avatar_url":"https://github.com/hdbr00.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Build it using C#\n\n[![progress-banner](https://backend.codecrafters.io/progress/http-server/3357626b-124f-4d56-9090-900013a94a0c)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)\n\n---\n\nThis repository contains a C# implementation of an HTTP/1.1 server. It is capable of handling multiple client connections concurrently and supports various HTTP features, including request parsing, header processing, file serving (from a specified directory), and Gzip content compression. This project was developed based on the CodeCrafters \"Build your own HTTP server\" challenge.\n\n## Implemented Features\n\n- [x] Bind to a port\n- [x] Respond with 200\n- [x] Extract with 200\n- [x] Extract URL path\n- [x] Respond with body\n- [x] Read header\n- [x] Concurrent connections\n- [x] Return a file\n- [x] Read request body\n- [x] Compression headers\n\n## Usage Examples\n\n### Root Path\n\nResponds with a simple 200 OK for the root path (`/`).\n\n```http\nGET / HTTP/1.1\nHost: localhost:4221\n\nHTTP/1.1 200 OK\nConnection: keep-alive\n```\n\n### Echo Service\n\nThe `/echo/{message}` endpoint returns the `{message}` part of the URL path in the response body. It supports Gzip compression if the client includes `Accept-Encoding: gzip` in the request headers.\n\n**Without Gzip compression:**\n```http\nGET /echo/hello-world HTTP/1.1\nHost: localhost:4221\n\nHTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 11\nConnection: keep-alive\n\nhello-world\n```\n\n**With Gzip compression:**\n```http\nGET /echo/hello-world HTTP/1.1\nHost: localhost:4221\nAccept-Encoding: gzip\n\nHTTP/1.1 200 OK\nContent-Encoding: gzip\nContent-Type: text/plain\nContent-Length: 30\nConnection: keep-alive\n\n[compressed content of \"hello-world\"]\n```\n\n### User-Agent Information\n\nThe `/user-agent` endpoint returns the value of the `User-Agent` header from the request body.\n\n```http\nGET /user-agent HTTP/1.1\nHost: localhost:4221\nUser-Agent: (Windows NT 10.0; Win64; x64)\n\nHTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 41\nConnection: keep-alive\n\n (Windows NT 10.0; Win64; x64)\n```\n\n### File Operations\n\nThe server can serve files from a directory specified using the `--directory \u003cpath\u003e` command-line argument. The `/files/{filename}` endpoint allows for creating files (via POST) and retrieving files (via GET).\n\n**Creating a file (POST):**\nThe content of the request body will be written to the specified file.\n```http\nPOST /files/tmp.txt HTTP/1.1\nHost: localhost:4221\nContent-Length: 18\n\nThis is a test file\n\nHTTP/1.1 201 Created\nConnection: keep-alive\n```\n\n**Retrieving a file (GET):**\nThe content of the specified file will be returned in the response body.\n```http\nGET /files/tmp.txt HTTP/1.1\nHost: localhost:4221\n\nHTTP/1.1 200 OK\nContent-Type: application/nest-kit\nContent-Length: 18\nConnection: keep-alive\n\nThis is a test file\n```\n\n**Attempting to retrieve a non-existent file (GET):**\n```http\nGET /files/nonexistent.txt HTTP/1.1\nHost: localhost:4221\n\nHTTP/1.1 404 Not Found\nConnection: keep-alive\n```\n\n## Building and Running\n\n### Prerequisites\n\n- .NET SDK (Version 9.0 or compatible, as specified in `codecrafters-http-server.csproj` and `codecrafters.yml`)\n\n### Building\n\nTo build the project, navigate to the repository root and run:\n```bash\ndotnet build --configuration Release --output /tmp/codecrafters-build-http-server-csharp codecrafters-http-server.csproj\n```\nThis command compiles the server and places the output in the `/tmp/codecrafters-build-http-server-csharp` directory (the exact output path might vary slightly based on your OS and .NET setup).\n\n### Running\n\nThe server can be run using the provided shell script `your_program.sh`, which handles the build process and then executes the server:\n```bash\n./your_program.sh\n```\n\nAlternatively, you can run the compiled executable directly after building:\n```bash\n/tmp/codecrafters-build-http-server-csharp/codecrafters-http-server\n```\n\nBy default, the server listens on port 4221.\n\n**Serving files from a directory:**\n\nTo enable file serving capabilities (for the `/files/` endpoint), start the server with the `--directory` argument, specifying the path to the directory from which files should be served:\n```bash\n./your_program.sh --directory /path/to/your/files\n```\nOr, if running the executable directly:\n```bash\n/tmp/codecrafters-build-http-server-csharp/codecrafters-http-server --directory /path/to/your/files\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhdbr00%2Fcf-http-server-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhdbr00%2Fcf-http-server-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhdbr00%2Fcf-http-server-csharp/lists"}