Serves html with html templates over HTTP/1.1.
Find a file
Stephen Seo cdacfc106d
All checks were successful
Build for Releases / ensure-release-exists (push) Successful in 3s
Build for Releases / push-build-x86_64 (push) Successful in 6s
Build for Releases / push-build-aarch64 (push) Successful in 1m12s
Build for Releases / push-build-x86_64_debian (push) Successful in 33s
Build for Releases / push-build-aarch64_debian (push) Successful in 2m5s
Run Unit Tests / build-and-run-unit-tests (push) Successful in 2m0s
Add strip --strip-unneeded to debian builds (ci)
2024-11-12 13:49:19 +09:00
.forgejo/workflows Add strip --strip-unneeded to debian builds (ci) 2024-11-12 13:49:19 +09:00
example_config Move test static file to "example_static_dir/" 2024-10-30 15:41:07 +09:00
example_static_dir Move test static file to "example_static_dir/" 2024-10-30 15:41:07 +09:00
src Impl. copying over "static-dir" files on generate 2024-11-11 15:09:12 +09:00
third_party Update third-party submodule SimpleArchiver 2024-10-30 14:42:27 +09:00
.gitignore Update .gitignore 2024-09-22 14:26:50 +09:00
.gitmodules Add third_party SimpleArchiver (data structures) 2024-08-30 11:58:11 +09:00
Changelog.md Update Changelod.md, version 1.2 2024-11-12 12:04:36 +09:00
CMakeLists.txt Cleanup by separating "generate" to source files 2024-11-10 21:06:41 +09:00
LICENSE Add the ISC LICENSE 2024-08-29 16:09:19 +09:00
Makefile Cleanup by separating "generate" to source files 2024-11-10 21:06:41 +09:00
README.md Update README.md 2024-11-12 12:06:21 +09:00

C Simple HTTP

A simple HTTP/1.1 server written in C.

Usage

Usage:
  -p <port> | --port <port>
  --config=<config_file>
  --disable-peer-addr-print
  --req-header-to-print=<header> (can be used multiple times)
    For example: --req-header-to-print=User-Agent
    Note that this option is case-insensitive
  --enable-reload-config-on-change
  --enable-cache-dir=<DIR>
  --cache-entry-lifetime-seconds=<SECONDS>
  --enable-static-dir=<DIR>
  --generate-dir=<DIR>
  --generate-enable-overwrite

Changelog

See the Changelog.

Before Compiling

Make sure that the git submodule(s) are loaded:

git submodule update --init --recursive --depth=1 --no-single-branch

Without this, the project will fail to build.

Example

# Build the project.
make c_simple_http

# Alternatively, build with cmake.
cmake -S . -B buildDebug && make -C buildDebug

# Run it with the example config.
# Note that the example config was designed such that it must be referred
# to from its parent directory.
./c_simple_http --config=example_config/example.config --enable-static-dir=example_static_dir
# If built with cmake:
./buildDebug/c_simple_http --config=example_config/example.config --enable-static-dir=example_static_dir

# If port is not specified, the server picks a random port.
# This program should print which TCP port it is listening on.
# Sometimes the program will fail to rebind to the same port due to how TCP
# works. Either wait some time or choose a different port.

# Access the website.
# This assumes the server is hosted on port 3000.
curl localhost:3000

Other Notes

The config file can be reloaded if the program receives the SIGUSR1 signal.
The --enable-reload-config-on-change option automatically reloads the config file if the config file has changed.

The --enable-cache-dir=<DIR> option enables caching and sets the "cache-dir" at the same time. --cache-entry-lifetime-seconds=<SECONDS> determines when a cache entry expires. The default expiry time of a cache entry is 1 week.