A basic implementation of an HTTP server done in c++! Linux and Windows friendly too 🙂.
Explore the docs »
Report Bug
·
Request Feature
Table of Contents
This is basically a mini project showing one of the major ways in which HTTP servers are implemented. In summary, it uses a TCP socket to listen for incoming requests and sends back a basic HTTP response based on standards set by the RFC documents.
As previously mentioned, this implementation of an HTTP web server basically creates a TCP socket which:
- listens for incoming requests on a particular socket address (which is mostly a combination of an IP address and a network port)
- synchronously processes network connections from a queue of threads built up from the listening
- reads the message sent by a client over the network connection and sends some dummy HTTP response.
Of course, there are many many many ways in which this code can be improved and/or extended, so this is an FYI saying that this is mainly for educational purposes. Do not go off trying to build your own server from scratch for use within production-level projects. Asides from the obvious "try not to re-invent the wheel rhethoric", chances are (with almost a certainty) you will end up with very serious security-related problems.
Jump to Roadmap to see more details about the project structure and its implementation overview.
This is a pretty simple project with just one requirement:
- Docker (unless you want to build it manually, then you'd be needing C/C++ compiler).
You will need to have docker setup on your computer, which can be done fairly easily by following the steps on their official documentation. The version run with docker is the linux version of the HTTP server implementation.
With docker fully setup on your system:
- navigate to your desired project directory
- Clone the repo
(if you do not have git installed, take a brief detour and follow these instructions).
git clone https://github.com/OsasAzamegbe/http-server.git
- navigate to the project folder http-server/ and build the docker image
docker-compose build
- start the server
docker-compose up
When you're done with the server and need it shut down:
- open up a second terminal window and navigate to the project folder
- bring down the docker container
docker-compose down
NOTE: if you make any changes to the code, you will have to re-compile as well by simply running step 3 again.
instructions coming soon
Once your server is up and running with docker-compose up
, you can pop into any web browser and navigate to localhost:8080/
to see the default HTTP response sent from the server. There will be an article coming soon where I'll talk more indept about the development of this HTTP server.
For more details, please refer to the Roadmap or the article (link coming soon)
instructions coming soon
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Osamudiamen Azamegbe
Medium
osas.azamegbe@gmail.com
Project Link: https://github.com/OsasAzamegbe/http-server