Download

minserv

A miniature server

  • C
Docs 655 wordsMarkdown 486Text 169
Binary data 13.2 KiBJPEG 11.2 KiBICO 2 KiB
NameModifiedLinesSize
example/ 433 lines43% of this folder's lines: 390 lines of code, 43 lines of docs 22.1 KiB54% of this folder's bytes
LICENSE 20 lines2% of this folder's lines 1.1 KiB3% of this folder's bytes
Makefile 49 lines5% of this folder's lines 1.3 KiB3% of this folder's bytes
README.md 59 lines6% of this folder's lines 2 KiB5% of this folder's bytes
get.sample 9 lines<1% of this folder's lines 349 B<1% of this folder's bytes
http-msg.c 146 lines15% of this folder's lines 4.5 KiB11% of this folder's bytes
minserv.c 239 lines24% of this folder's lines 8.5 KiB21% of this folder's bytes
minserv.xinetd 15 lines1% of this folder's lines 264 B<1% of this folder's bytes
post.sample 15 lines1% of this folder's lines 507 B1% of this folder's bytes
utils.h 20 lines2% of this folder's lines 409 B<1% of this folder's bytes

README.md

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