c_simple_http/README.md

67 lines
2.3 KiB
Markdown
Raw Normal View History

# 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
2024-09-10 05:00:57 +00:00
--enable-reload-config-on-change
2024-09-26 03:38:51 +00:00
--enable-cache-dir=<DIR>
--cache-entry-lifetime-seconds=<SECONDS>
2024-10-30 05:42:00 +00:00
--enable-static-dir=<DIR>
2024-11-12 03:06:21 +00:00
--generate-dir=<DIR>
--generate-enable-overwrite
2024-11-07 04:34:06 +00:00
## Changelog
See the [Changelog.](https://git.seodisparate.com/stephenseo/c_simple_http/src/branch/main/Changelog.md)
2024-09-06 04:16:31 +00:00
## 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
2024-09-06 04:47:31 +00:00
# Alternatively, build with cmake.
cmake -S . -B buildDebug && make -C buildDebug
# Run it with the example config.
2024-09-06 04:47:31 +00:00
# Note that the example config was designed such that it must be referred
# to from its parent directory.
2024-10-30 06:41:56 +00:00
./c_simple_http --config=example_config/example.config --enable-static-dir=example_static_dir
2024-09-06 04:47:31 +00:00
# If built with cmake:
2024-10-30 06:41:56 +00:00
./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
2024-09-10 05:00:57 +00:00
## 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.
2024-09-26 04:04:58 +00:00
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.
2024-09-26 07:33:07 +00:00
[The default expiry time of a cache entry is 1 week.](https://git.seodisparate.com/stephenseo/c_simple_http/src/commit/3f1be0cf496eab7242ab997262d85af11337039b/src/constants.h#L28)