SHTTPD (Simple HTTP Daemon)

Overview

SHTTPD is tiny, easy to use web server for Windows and UNIX. Ideal for web developers, web-based software demos (like PHP, Perl etc), quick file sharing, personal use. It also can be used as a library that provides web server functionality, to create web interface for C/C++ applications. SHTTPD is licensed under the terms of beerware license.

Download

Get the latest version. Read the manual.

Features

Absent features: virtual hosts, user home directorires, traffic shaping, FCGI (Fast CGI) support.

Tips for Windows users

SHTTPD old-timers may notice that the GUI, which included system tray icon, settings window and logging window, has gone as of release 1.40. This is due to the fact that the GUI introduced many confusing problems, since the code logic for GUI version was different with console version. However, as of version 1.40, a Windows service feature has been introduced, which allows to run SHTTPD in the background as a service. For those who do not want to run a service, and annoyed by a console window that appears when SHTTPD starts, a special option, "-systray yes", has been added. Configuration options, as always, can be specified in shttpd.conf file, which should live in the same directory as shttpd.exe, or in the shortcut. There is a chance that the GUI will be back soon.

Making HTTP proxy server

Install Perl on your machine. Download nph-proxy.cgi perl script, developed by James Marshall. Start shttpd, set the option "CGI interpreter" to perl binary (perl.exe on Windows). In a browser, type in the URL where nph-proxy.cgi lives. That's all.

Embedding SHTTPD into existing application

Download the source package. Extract it, go to src directory. Run "make unix" there ("nmake win" on Windows, requires MSVC). That buillds a library. The API is defined in shttpd.h header file. Use the API functions in your application, link the application against the library. There are couple of examples in the source package you can refer to.

Issues I came across (information for developers)

SHTTPD internals (information for developers)

SHTTPD can operate in single-threaded or multi-threaded mode. For each thread of execution, a worker descriptor is created that contains all information about connected sockets. All workers share the same configuration context. There is only one worker per thread. Each worker utilizes FSM (finite state machine) model to handle multiple connections simultaneously. select() system call is used to multiplex the connections. When a new socket is connected, a connection descriptor is allocated, which holds all data describing the connection, as well as the IO buffers. During connection lifetime, no more dynamic allocations are performed.

select() call multiplexes three kinds of sockets: connected client sockets, listening sockets and a control socket. Control socket is used in two cases: in multithreaded mode, main context only accepts new sockets and passes them to the worker threads via the control socket. The other case where control socket is used, is an embedded case: if user callback function wants to suspend its output until some event, it sets the suspend flag and exits. Later on, the user code can wake up the connection by sending the control message to a control socket.

The use of control socket eliminates the need of synchronization usually needed in multithreaded application, and allows to use single select() loop for multiplexing all possible events.

SHTTPD does not spawn new thread per connection. Main thread accepts new connections, and passes accepted sockets to a worker threads. Worker threads handle them using FSM model, as stated above. This allows for the best performance. If there is only one worker (the default), both main thread and a worker execute in the same thread.

For the BSD architecture, experimental sendfile() API could be enabled at compilation time, which gives significant boost for serving static content.

License

 "THE BEER-WARE LICENSE" (Revision 42):
 Sergey Lyubka wrote this software. As long as you retain this notice you
 can do whatever you want with this stuff. If we meet some day, and you think
 this stuff is worth it, you can buy me a beer in return.

Links

Acknowledgements

My wishlist

I have a books wishlist on Amazon. If you feel brave, you can by me a book!

Author

Copyright © by Sergey Lyubka (shttpd-general at lists dot sourceforge dot net). My other projects worth mentioning: