About websrv

A small, lightweight and easy-to-use HTTP/1.0:ish web server for static files. It is intended to be used as a quick one shot web server for sharing files on a LAN or as a local server for client side web development.

Supported HTTP methods are GET and HEAD. Connections are always closed after one request. The response always includes HTTP headers even if the request is in old HTTP/0.9 style, for example GET /\r\n.

File transfers should be reasonable efficient as they are implemented using sendfile() on Linux and FreeBSD, and TransmitFile() on Windows NT. (Windows 9x has to fallback to a read() & send() loop.) Large files (over 2 GiB) have not been tested and probably will not work.

IPv6 is not currently supported (patches are welcome.) There will "never" be HTTPS (SSL/TLS) support.

I have yet to find a web browser or a command line client that does not work nicely with websrv even though I know it is not standard compliant by any means.

Requirements

websrv has been primarily developed on Linux and tested on various Windows versions ranging from Windows 98 to Windows 10, as well as FreeBSD 10.

It requires about 1.5 MiB of free memory. More is of course better so that OS can use it for caching the file system.

The provided Windows .exe is compiled for i686 and will not work with anything less than a Intel Pentium Pro / Pentium II / AMD K6. It works fine in 64-bit Windows. You can (re)compile for i586 by deleting the -march=i686 in the Makefile.

Compiling

Compiling from source requires a C compiler with working C99 support and GNU Make. websrv has been successfully compiled with both GCC and Clang on Linux and FreeBSD, and with MinGW on Windows.

Simply running make (or gmake) should work and make DEBUG=1 compiles a debug build. See Makefile for more.

Usage

There are no configuration files. Few options can be set with command line parameters:

Usage: websrv [-h|--help] [-a x.x.x.x] [-p n] [-t n] [-i idx.htm] [-m mime.txt] [dir]
Where:
  -h, --help   Print usage
  -a x.x.x.x   Set listen IPv4 address (default: 127.0.0.1)
  -p n         Set listen TCP port (default: 8000)
  -t n         Set number of threads (default: 4)
  -i idx.htm   Set default page(s) (default: index.html,index.htm,default.html,default.htm)
  -m mime.txt  Load MIME table from a file (default: built-in)
  dir          Set webroot (default: .)

The default when run without arguments (or double clicked in Windows) is to serve files from the current directory for localhost only at address http://127.0.0.1:8000/. In the absense of an index file, websrv will list the directory contents. There is a built-in favicon if one is not found in the root directory.

See MIME.txt for more about the MIME table file. (The one exception to "no configuration files" ;-)

Production build prints a couple of message lines at start and the web log style lines for each request to stdout. Any errors are printed to stderr.

License

Copyright © 2016 Väinö Helminen

Licensed under a MIT license. See included LICENSE for more.

2016-07-05 23:35:03 UTC

Screenshots

Windows 10

Apparently Edge doesn't try to load favicon.ico if there isn't a link to it in the HTML.

websrv on Microsoft Windows 10

Windows 7

I wonder what those empty connections ("" 400 0) are that occasionaly happen with some browsers on Windows.

websrv on Microsoft Windows 7

Windows 98

websrv on Microsoft Windows 98

Arch Linux

This screenshot shows an example directory listing that websrv generates if no index file is found.

websrv on Arch Linux

FreeBSD

websrv on FreeBSD

2016-07-05 23:35:03 UTC

Download

2016-07-05 23:35:03 UTC

Contact Me

You can send me feedback about websrv or anything else using this web form.