Simple HTTP Server
This project is a simple HTTP server that can serve static files. I had big plans for POST request support, a templating engine, and backend features, but just serving files turns out to be quite a lot of work, and I unfortunately ran out of time.
For bureaucratic reasons I took a 100 level CS course in my senior year, and since I had no final exams I went totally overboard for my final project. I always wanted to write my own HTTP server, and the final project was the perfect excuse to actually do it. Because of the scope of the program I consider it more of a personal project than a school assignment since I went FAR and above the assignemnt requirements just for the fun of it.
In hindsight there were a lot of decisions I would make differently around code architecture and organization, but I learned so, SO, much doing this project. It has definitely been worth the effort and mistakes even if it's a litte rough around the edges.
How to use
The project is designed to be very straightforward to run. It includes a Makefile and a Dockerfile. It should work on any linux system with build-essential. I have used Ubuntu for development. If you are unsure of your environment or running on a non-linux system, then running it in a docker container is the easiest way to go.
Deploying as a docker container
- Make sure docker is installed on your system.
- Clone the repository by running
git clone https://github.com/COS135-S2025/project-GShadow5.git - Run the container by running
docker compose upin the project root directory. (command may bedocker-compose upon some versions and platforms) - Navigate to http://localhost:8080/index.html in your browser.
- Navigate to other files found in the
publicdirectory, such as http://localhost:8080/image.png and http://localhost:8080/script.js - To stop the server you can hit ctrl+c in the terminal, or type
qand hit enter.
Building from source
- If gcc and make are not installed, install them by running
sudo apt-get install build-essential - Clone the repository by running
git clone https://github.com/COS135-S2025/project-GShadow5.git - Build the project by running
makein the project root directory (where the Makefile is). - Run the server by running
./webserver.outin the project root directory. - Navigate to http://localhost:8080/index.html in your browser.
- Navigate to other files found in the
publicdirectory, such as http://localhost:8080/image.png and http://localhost:8080/script.js - To stop the server you can hit ctrl+c in the terminal, or type
qand hit enter.
TODO List
- Get basic HTTP interaction working
- Get url parsing working
- Fix existing bugs in socket handling and TCP buffering
- Finish code to parse HTTP requests
- Update makefile to be more flexible
- Add enums for method types
- Add switch statement to handle different request types
- Add functions to handle each request type
- Finish code to build HTTP responses
- Get html file serving working
- Add flexible logging with variadic arguments
Make html page for uploading filesGet POST requests workingImplement file uploads (with restricted file types)Implement file indexing and serving a directory pageCreate basic templating engine for HTML working- Publish as a portfolio project
Known issues
There is an issue where the CSS file is not being received properly when included in an HTML file on Firefox based browsers. It works fine on Chromium based browsers, and Firefox loads the CSS file just fine when loaded directly, so I'm not sure what the issue is. If Firefox is behaving strangely try it with something Chromium based.
I have not debugged the issue yet becayse I'm not hung up on broad compatability for the scale that this project is at, and it works fine on Chromium browsers.
References
- HTTP status codes
- How I built a simple HTTP server from scratch using C: I used this to understand how to get started, but exapanded from it a lot.
- strtok reference: Didn't end up using strtok, but it was one of the approaches I tried for parsing the incoming requests.
- Variadic arguments references:
- I did not use any references for multithreading as I have used pthreads extensively for the last few semesters.
- Makefile reference: Used a bunch of this to understand how to write more complex makefiles.