This is not like prod-ready server or anything. The purpose of this project was to learn the internal mechanism of how a typical HTTP server works. Here I have built a simple server for HTTP/1.1
protocol.
Following are the things which I learned:
- Establishing connection via TCP server.
- Reading the client request.
- Parsing the client request (Request line, Headers & Body).
- Forming the response (Status line, Headers & Body).
- Sending the response back to the client.
- Handling multiple clients (i.e., concurrent connections)
- Handling signal sent from terminal running the server.
- Sending over the file to client upon request.
- Learn some bits about HTTP compression mechanism.
- Parsing for the multiple compression schemes.
- Support for Gzip compression.
The project is written in Zig programming language. The experience to use this language was pleasant. I would encourage for people to try it out. The comunity of the language although relatively small, has been a helping one. I would continue doing some other projects on this language.
Here are the steps to build the project:
- Follow the steps mentioned on the zig's official site and setup the language.
- Run the command
zig build-exe src/main.zig
to build the executable - Simply run the executable as
./main
The following project was done as part of Codecrafters challenge. You can read more about the codecrafters from below.
This is a starting point for Zig 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.