GWS - The Ghetto Webserver
(C) 2006, Ben Cantrick
Welcome to the home page of the Ghetto Webserver. This is a quick hack, non-HTTP/1.0 complaint webserver I coded up in an afternoon, and refined a bit in another. It's written in plain C, using the UNIX sockets API. The original version was ~180 lines, current is ~250 lines. I'm putting it up in the hope that it may be useful and/or interesting for people attempting to learn sockets, or those who want a simple example of a webserver implementation without too much extra crud that might obscure the basic functionality, or people looking for an EXTREMELY simple, single-threaded, lightweight and free-as-in-beer webserver for embedded applications.
This code is distributed under the modified BSD license. Share and enjoy freely, but give credit where credit is due.
gws20060208.tgz - Version alpha 3. Header handling has been improved to be more robust. Code has been modularized a bit more and readability is a lot better. Thanks to Alex Belits for patches for Linux compatability and typo correction. Several little tweak opportunities if anyone wants them: There is still no header parsing to speak of, so the file index.html is always served. The code makes no attempt to distinguish between 404 (file not here) and 403 (permission to open file denied) errors. The entire output file should be sucked up in NETBUFF_SIZE chunks and sent out a buffer at a time, instead of going one line at a time as the fgets() code in sendFile() does now. Also, the GWS still doesn't fork(), and is still not HTTP-1.0 compliant, but those are both per design spec.
gws.c - This is the source code. (Yes, all of it.) To save people browsing for examples the trouble of undoing a TGZ file.