This is a starting point for Rust solutions to the "Build Your Own HTTP server" Challenge.
HTTP is the protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server that is capable of serving multiple clients.
Along the way you'll learn about TCP servers, HTTP request syntax, and more.
Note: If you're viewing this repo on GitHub, head over to codecrafters.io to try the challenge.
The entry point for your HTTP server implementation is in src/main.rs. Study
and uncomment the relevant code, and push your changes to pass the first stage:
git commit -am "pass 1st stage" # any msg
git push origin masterTime to move on to the next stage!
Note: This section is for stages 2 and beyond.
- Ensure you have
cargo (1.82)installed locally - Run
./your_program.shto run your program, which is implemented insrc/main.rs. This command compiles your Rust project, so it might be slow the first time you run it. Subsequent runs will be fast. - Commit your changes and run
git push origin masterto submit your solution to CodeCrafters. Test output will be streamed to your terminal.
This is a collection of TODOs of possible improvements/refactors that I feel would make this project more elegant / reusable / etc, but do not have the time for right now:
- Create a
Serverstruct that keeps configuration, eg,--directory - Use of macros for building routes
- Builder pattern
- Separate framework from functionality for passing CodeCrafters test(s)
- Due to adding support for reading body,
Request::decodegot a little unwieldy. I am tempted to havenew()read all the bytes from the stream intobytes_received, soRequestcan use references. - Validate that the body sent is the
content-lengthclient provided - 100% branch coverage (time consuming 😅)
- Various improvements to testing - should the CodeCrafters tests be integration? should there be helpers for parsing responses? etc...
- Profile performance and fuzz
- Reimplement using a streaming approach (vs read-then-parse of today). I intentionally avoided to KISS (Keep It Simple Silly) and make forward progress.
- Protection from clients that drip-feed bytes (see
main.rs>RECEIVE_TIMEOUT)