Last modified: 2022-09-06 10:37

userver - micro HTTP server and gawk extension

userver is a minimal HTTP server where additional options are added at compile-time. Use-cases are e.g.

The HTTP protocol is very limited, just what is needed to serve requests with some support for Gopher protocol (I plan to make that optional.) and the level of HTTP implementation compares well to Gopher protocol: The client requests a file and the server sends it. userver

Protocol support may be enhanced in future releases.

Optional Features

Compiling userver.c without any options gives the core server that can handle only static files. This is what I would use to run it on the Internet from home assuming that the software is secure enough (statically linked, locked in a chroot(7) jail, with apparmor(7) on it, behind a firewall, if possible on a minimal Linux).

Depending on the particular use-case, additional features can be added at compile-time. See the manpage to understand userver's functionality and what the options do (and what not).

Downloads

There are Debian archives

and the source tgz. The Debian archives install a default userver in /usr/bin and the gawk extension, source and makefile userver.make in /usr/lib/userver. I understand that distributing the source is quite unusual but compiling your own version is a central point.

In case you never compiled before, you need (in Debian terms)

$ sudo apt-get install gcc binutils make

Add ctags is you like. Options can be added in the userver.make and

$ make

creates a new userver and userver.so.

Run

$ userver -V
userver 1.0.0-beta1
  -DWITH_DIR_LISTING
  -DWITH_LOCAL_IDENTITY
  -DWITH_REGEX_MAP
  -DWITH_START_AS_ROOT
  -DWITH_UPLOADS

to check the activated options in the pre-compiled binary.

Compiling

There is only userver.c to compile and that is simple to do:

$ gcc -o userver -DWITH_DIR_LISTING -DVERSION=\"1.2.3\" userver.c

The version number is optional and undefined if not set. Verify that you made the right combination:

$ ./userver -V
userver 1.2.3
  -DWITH_DIR_LISTING

-V lists all compiled options. You can add the -Wall option to gcc and it should return two types of warnings:

Instead of calling the compiler directly you can also set your desired options in userver.make and run make -f userver.make userver.

userver.make can also produce the gawk extension. If you prefer to create it from the command line you would run

   $ gcc -o userver.so your-options-here -DAS_EXTENSION userver.c -shared

Code Maturity

This is a beta release. I use userver at home for small servers running on Raspberry Pis for this and that. I expect to find bugs (even stupid ones) and will fix then and add new features as I find them. I would not use this release for prime-time on Internet.

Wishlist

I already have some more options on my "things to add" list:

Code Reviews

userver comes in a single source file and #ifdef's are scattered all over it, which may make it somewhat difficult to read. The script spp pre-processes the file based on -D options and prints the result, removing unselected options. E.g.

spp -DWITH_DIR_LISTING userver.c

prints the base code plus the source required for WITH_DIR_LISTING. There are two interesting options.

-c
produce source that can be compiled without giving any -D options to gcc. (The output is similar than to without -c but all #ifdef's are removed.)

-s
print only the source of the given options. Helpful to see how a particular option is implemented.

The script is not perfect and adapted to my style of source formatting, which is really not main-stream.

Background

userver started as HTTP server for static files from a simple question: Can I can make a web server with a code basis that I trust enough to use it as public server from home? Central aspects would be

A first version was ready with approx. 1500 lines of code (30 kB) and then the usual thing happened. Features were added to pursue another goal: What would I want from a server for private, home-only (not public) use? Functionality is all about the use-case. Sometimes static files are enough and sometime CGI is needed. But I also don't want to have different code bases. I noticed that I can add all kind of features to userver and that's fine as long as there is a compile-time option for it. I can have the core static-files-only version at any time I like.

Why is this important, why not simply use an off-the-shelf product? They are often very "feature rich". And you have to take care about dependencies and their interactions, more features mean more possibilities for misconfiguration and more lines of code often come with more bugs. There are long-running projects like apache with less bugs but they are simply too large for my taste.

Then, as far as I know, they can't be used as gawk extension. And finally, not to forget, there's the fun to code.