A simple, static-content-only HTTP server that builds as a static binary, suitable for deployment inside a container.
Go to file
Greg S. ed7180b7f2 Add link options for static linking pthread.
Added container script using buildah.
2023-03-19 12:02:05 -04:00
ss4sc Add automatic content-type determination. 2023-03-11 09:30:56 -05:00
test Initial code import. 2021-10-11 17:04:18 -04:00
.gitignore Initial code import. 2021-10-11 17:04:18 -04:00
CMakeLists.txt Add link options for static linking pthread. 2023-03-19 12:02:05 -04:00
COPYING Initial code import. 2021-10-11 17:04:18 -04:00
README.rst Update README for additional utility programs. 2021-10-17 21:38:17 -04:00
automime-main.cpp Add automatic content-type determination. 2023-03-11 09:30:56 -05:00
automime.cpp Add automatic content-type determination. 2023-03-11 09:30:56 -05:00
create-dirindex.cpp Add some simple automation tools. 2021-10-15 17:08:45 -04:00
http_connection.hpp Add automatic content-type determination. 2023-03-11 09:30:56 -05:00
ss4sc-attrs.cpp Initial code import. 2021-10-11 17:04:18 -04:00
ss4sc-container.sh Add link options for static linking pthread. 2023-03-19 12:02:05 -04:00
ss4sc-file-utils.cpp Add automatic content-type determination. 2023-03-11 09:30:56 -05:00
ss4sc-setattr.cpp Initial code import. 2021-10-11 17:04:18 -04:00
ss4sc.cpp Add link options for static linking pthread. 2023-03-19 12:02:05 -04:00

README.rst

This project is for a simple, static-content-only HTTP server that builds as a static binary, suitable for minimal deployment inside a container.

License

GPLv3

Language

C++

Dependencies
  • C++17 (std::filesystem, std::chrono)

  • Boost.Beast

  • Boost.Asio

  • Boost.Program Options

  • 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.

Supports:

  • ✓ HTTP/1.0, HTTP/1.1

  • ✓ OPTIONS, HEAD, GET methods

  • ✗ Etags + Conditional requests.

  • ✗ Range request for bytes.

  • ✗ Prometheus metrics

✓ = implemented ✗ = not (yet) implemented

Future Roadmap?

  • HTTP/2 (HTTP/3?)

  • TLS

  • 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.

ss4sc

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).

ss4sc-attr

Prints to stdout the set of header as determined by the file metadata for the file given as the command line argument.

e.g.

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.

ss4sc-setattr

Sets the relevant extended attributes on file(s) passed on the command line based on the passed options.

e.g.

./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.

ss4sc-automime

Scans files recursively from the current directory and sets the user.mime_type extended attribute (if not already present) on files that match conventional filename extensions:

  • .html, .htm => text/html

  • .txt, .log => text/plain

  • .css => text/css

  • .xml => text/xml

  • .xhtml => application/xhtml+xml

  • .xsl => text/xsl

  • .js => application/javscript

  • .png => image/png

  • .jpeg, .jpg => image/jpeg

  • .git => image/gif

Outputs what files are altered and the mime type the are set to.

ss4sc-dirindex

Recursively scans files from the current directory and writes an index HTML file (note that there is no extension) with appropriate extended attributes to be served as text/html containing a table of the directory's contained files, with some metadata about them.

Outputs which files are created. Does not overwrite pre-existing files named index, and stops directory traversal when one it encountered.