{"id":15099146,"url":"https://github.com/amitrajitdas/byo-http-server","last_synced_at":"2026-01-12T06:22:54.353Z","repository":{"id":251242737,"uuid":"832729090","full_name":"AmitrajitDas/BYO-HTTP-Server","owner":"AmitrajitDas","description":"Simple Go HTTP Server","archived":false,"fork":false,"pushed_at":"2024-08-01T16:25:02.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-26T04:33:40.941Z","etag":null,"topics":["buffered-reader","compression","curl","golang","gzip","http-server"],"latest_commit_sha":null,"homepage":"","language":"Go","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/AmitrajitDas.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}},"created_at":"2024-07-23T15:50:10.000Z","updated_at":"2024-08-01T16:25:05.000Z","dependencies_parsed_at":"2024-08-01T18:42:16.767Z","dependency_job_id":"3c6e2917-5a26-41be-80af-9c0cc63ee3fc","html_url":"https://github.com/AmitrajitDas/BYO-HTTP-Server","commit_stats":null,"previous_names":["amitrajitdas/byo-http-server"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmitrajitDas%2FBYO-HTTP-Server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmitrajitDas%2FBYO-HTTP-Server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmitrajitDas%2FBYO-HTTP-Server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmitrajitDas%2FBYO-HTTP-Server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmitrajitDas","download_url":"https://codeload.github.com/AmitrajitDas/BYO-HTTP-Server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246516821,"owners_count":20790301,"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":["buffered-reader","compression","curl","golang","gzip","http-server"],"created_at":"2024-09-25T17:06:27.111Z","updated_at":"2026-01-12T06:22:54.347Z","avatar_url":"https://github.com/AmitrajitDas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![progress-banner](https://backend.codecrafters.io/progress/http-server/6f27fabe-0738-464a-8665-9d7b62191a86)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)\n\n# Simple Go HTTP Server\n\nThis is a basic HTTP server written in Go. It listens on a specified port and handles various HTTP requests, including serving files, echoing content, and returning the User-Agent string.\n\n## Features\n\n- **Echo Endpoint:** Returns the content appended to `/echo/` in the URL.\n- **User-Agent Endpoint:** Returns the User-Agent string from the request.\n- **File Serving:** Serves files from a specified directory. Supports `GET` and `POST` methods.\n- **Gzip Compression:** Supports gzip compression based on the `Accept-Encoding` header.\n\n## Usage\n\n### Starting the Server\n\nTo start the server, run the following command:\n\n```sh\ngo run main.go [directory]\n```\n\n- **Directory (optional):** The directory from which to serve files. If not specified, the current directory will be used.\n\n## Endpoints\n### Echo Endpoint\n\n- **URL:** `/echo/{content}`\n- **Method:** `GET`\n- **Description:** Returns the `{content}` appended to the URL.\n\n### User-Agent Endpoint\n\n- **URL:** `/user-agent`\n- **Method:** `GET`\n- **Description:** Returns the User-Agent string from the request.\n\n### File Serving\n\n- **URL:** `/files/{filename}`\n- **Method:** \n   - **GET:** Serves the specified file.\n   - **POST:** Saves the content in the request body to the specified file.\n- **Description:** Serves or saves files in the specified directory.\n\n## Example Requests\n### Echo Content:\n```sh\ncurl http://localhost:4221/echo/hello\n```\n\n### Response:\n```sh\nhello\n```\n### Get User-Agent:\n```sh\ncurl http://localhost:4221/user-agent\n```\n\n### Response:\n```sh\ncurl/7.68.0\n```\n### Serve File:\n```sh\ncurl http://localhost:4221/files/example.txt\n```\n\n### Save File:\n```sh\ncurl -X POST -H \"Content-Type: text/plain\" -d \"This is a test\" http://localhost:4221/files/example.txt\n```\n\n## Implementation\nHere's a brief overview of the code structure:\n- **main.go:** The main entry point of the server.\n   - **main():** Starts the server and listens on the specified port.\n   - **handleConnection(conn net.Conn):** Handles incoming connections.\n   - **parseRequest(conn net.Conn):** Parses the HTTP request.\n   - **getStatus(statusCode int, statusText string):** Returns the HTTP status line.\n   - **getDirectoryFromArgs():** Returns the directory from which to serve files, defaulting to the current directory if not specified.\n\n## Error Handling\n- Returns 400 Bad Request for malformed requests.\n- Returns 404 Not Found for unknown paths or missing files.\n- Returns 405 Method Not Allowed for unsupported methods.\n- Returns 500 Internal Server Error for server-side errors during file operations.\n\n## Gzip Compression\nThe server supports gzip compression if the `Accept-Encoding` header includes `gzip`. Compressed responses include the `Content-Encoding: gzip` header.\n\n## License\nThis project is licensed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitrajitdas%2Fbyo-http-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famitrajitdas%2Fbyo-http-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famitrajitdas%2Fbyo-http-server/lists"}