A toy HTTP server I built while learning programming in C. It only supports HTTP/1.1 since I don't want to deal with implementing HTTP/2 framing, multiplexing, flow control, etc.
This project probably contains many errors and has little to no compliance with RFC 9112. Please do not use it for anything serious.
The project uses a simple Makefile. To build the server just run:
make
This will produce a simple-http executbale into a ./build directory. To clean build files:
make clean
This project will depend on OpenSSL for future TLS support. To build the project you will need OpenSSL development libraries installed on your system.
sudo apt install libssl-dev
sudo dnf install openssl-devel
sudo pacman -S openssl
simple-http [options]
The currently supported options are:
--host, -h: IP address the server will bind to--port, -p: Port used to serve HTTP--verbose, -v: Enable verbose logging--quiet, -q: Suppress logging--config, -c: Location of a.iniconfiguration file--tls-enabled, -s: Whether to support TLS--tls-key, -k: Location of the private key for TLS--tls-certificate, -r: Location of the certificate for TLS
The following settings can be configured in the configuration file using the format:
setting = value
By default, the program looks for a file in the current directory called conf.ini.
IP address the server will bind to.
Default value: 0.0.0.0
The port that the server will be bound to
Default value: 8080
Directory containing the static files that will be served.
Default value: ./
Path to the file (relative to doc_root) that will be served when requesting /.
Default value: index.html
Amount of time in seconds to wait before the server closes an idle connection.
Default value: 15
Logging level.
Accepted values: verbose, quiet, warn, informational
Default value: informational
Maximum number of concurrent connections allowed by the server.
Default value: 1024
Number of worker threads used to handle incoming HTTP requests.
Default value: 8
Location of the TLS certificate file.
Default value: ./server.crt
Location of the TLS private key file.
Default value: ./server.key
Whether TLS will be enabled.
Accepted values: true, false
Default value: false
# conf.ini
host = 0.0.0.0
port = 8443
doc_root = ./
index_file = index.html
keepalive_timeout = 15
log_level = informational
max_connections = 1024
workers_number = 8
tls_enabled = false
tls_certificate = ./server.crt
tls_key = ./server.key
- Multithreading
- Persistent connections
- Better HTTP/1.1 compliance
- TLS support with OpenSSL
- Read configuration from a file
I don't expect to finish everything on this list, but I will try.