minserv
minserv is a minimal server that pairs with xinetd. It reads HTTP requests
from STDIN and prints HTTP responses to STDOUT. It's based around simple
shell scripts and executable files, so it's fairly language-agnostic.
Requirements
minserv is designed for xinetd, though in theory, it could work with
systemd or inetd. I haven't tried. Otherwise, the only requirement is awk,
which is used for URL decoding.
Installation
sudo make install
Architecture
Your web server will route requests to <root>/<URI>. By default, <root> is
/var/www. For example curl localhost/foo/baz would route to
/var/www/foo/baz by default. The first argument provided to minserv is
used as <root>.
HTTP Parameters
GET parameters will be available as environment variables like $GET_foo,
POST parameters as $POST_foo. The HTTP request's method is available as
$METHOD.
Routing
All routing is handled by an executable program in your server's root called
.handler. This file will be given the request path as its only parameter
and it's expected that it will either return a valid HTTP response (probably
using http-msg), or exit with failure, triggering a 500 Internal Server Error.
The default .handler file (default_handler) has some
examples for useful behaviors, like routing /foo to /foo.html if it exists,
or routing /baz to a converted-on-the-fly markdown file /baz.md, or running
executable cgi scripts.
HTTP-msg
A small helper program (written in C) is provided, http-msg, which facilitates
making well-formed HTTP responses.
Errors
You can use minserv . N to trigger an HTTP N error. Currently, only N = 404 and N = 500 are supported (though expanding support is trivial).
Demo
The demo requires Pandoc to showcase on-the-fly markdown to HTML conversion.
sudo mkdir -p /var/www && ./example/sync
Then open your browser to http://localhost