ss4sc-dirindex: Generate index files for directories. ss4sc-automime: Based only on file extension, automatically assign user.mime_type attributes to files.
|10 months ago|
|ss4sc||10 months ago|
|test||10 months ago|
|.gitignore||10 months ago|
|CMakeLists.txt||10 months ago|
|COPYING||10 months ago|
|README.rst||10 months ago|
|automime.cpp||10 months ago|
|create-dirindex.cpp||10 months ago|
|http_connection.cpp||10 months ago|
|http_connection.hpp||10 months ago|
|ss4sc-attrs.cpp||10 months ago|
|ss4sc-file-utils.cpp||10 months ago|
|ss4sc-setattr.cpp||10 months ago|
|ss4sc.cpp||10 months ago|
This project is for a simple, static-content-only HTTP server that builds as a static binary, suitable for minimal deployment inside a container.
C++17 (std::filesystem, std::chrono)
Filesystem supporting extended attributes.
sysconf() library support.
Served resources are files in the filesystem.
URL based on path from docroot.
No implicit content-type guessing.
Filesystem extended attributes are used to populate header information:
✓ user.mime_type populates Content-Type (if not populated, application/octet-stream)
✓ user.charset populates the ;charset= on Content-Type (if not populated, no parameter is added)
✓ user.xdg.language populates Content-Language (if not populated, no parameter is added)
✓ user.e6l.ss4sc_headers populates additional (fixed) headers on the resource.
✓ HTTP/1.0, HTTP/1.1
✓ OPTIONS, HEAD, GET methods
✗ Etags + Conditional requests.
✗ Range request for bytes.
✗ Prometheus metrics
✓ = implemented ✗ = not (yet) implemented
Content negotiation (content-encoding, content-language, content-type) - pre-computed only (anything else would be 'dynamic' content)
Build using standard CMake invocations:
mkdir build cd build && cmake ../ cmake --build build
Creates the following binaries: ss4sc, ss4sc-setattr, ss4sc-attr.
Any unsupported HTTP method results in a 405 Method Not Supported response with an Allow header indicating only GET, HEAD, and OPTIONS are permitted.
An OPTIONS request for * is will return a 200 Ok with generic server headers populated.
An OPTIONS request for a file that exists will return headers populated as for that file, with no content. (As will a HEAD request, though the HEAD request returns the Content-Length of the resource.)
A request targeting a file that does not exist gets an empty 404 Not Found response. (With the default server headers).
The Server header is automatically populated on all responses with a value of ss4sc/[version].
The Last-Modified, Date, and Content-Length headers are automatically populated based on file metadata, and system information.
The Last-Modified time is based on a heuristic comparison with the system clock and the file clock; C++20 will allow a direct conversion without the heuristic.
A directory resource will be returned by the file named index within that directory (Note that there is no file extension).
An automatic Link header with rel=cannonical is generated based on the discovered file path.
For directory indexes, the cannonical URL is the directory name without the trailing slash.
For files, the cannonical URL is the file path from the docroot.
URLs with .. in their components get a 400 Bad Request response (they are not allowed)
URLs requested with redundant / separators are normalized, and unneeded . components are removed.
The docroot is the current working directory of the ss4sc binary when launched.
The listen port defaults to 8888, using an IPv6 wildcard socket accepting IPv4-mapped addresses.
To select a different listening port, invoke the binary with the port number as the first argument. (e.g. ss4sc 8080)
A number of worker threads are started based on the results of sysconf(_SC_NPROCESSORS_ONLN) (the logical number of online processors as seen by the OS).
Prints to stdout the set of header as determined by the file metadata for the file given as the command line argument.
enimihil@merida ss4sc$ ./build/ss4sc-attrs README.rst For file: "README.rst" HTTP/1.1 200 OK Content-Type: text/x-rst; charset=utf-8 Last-Modified: Mon, 11 Oct 2021 20:37:34 GMT Date: Mon, 11 Oct 2021 20:38:20 GMT Content-Length: 2563
When README.rst file has user.mime_type set to text/x-rst and user.charset set to utf-8.
Sets the relevant extended attributes on file(s) passed on the command line based on the passed options.
./build/ss4sc-setattr --content-type text/x-rst --charset utf-8 *.rst
This command would set all the *.rst files in the current directory to have a user.mime_type xattr of text/x-rst and a user.charset xattr of utf-8.