A small foot print, non-blocking, single threaded HTTP web server with support for non-POSIX TCP sockets written in C

Similar projects worth following
BittyHTTP is a small web server written in C.

BittyHTTP's features are:
* Does not need an OS
* Does not need a file system (pages are served directly from C code)
* Works with non-standard TCP sockets
* Supports Cookies
* Supports POST
* Supports GET
* Embeddable into other C/C++ programs.

BittyHTTP has a few functions you must provide and a few functions you must call from your application (provided you use the POSIX SocketsCon.c).

The functions you must provide are:

  • ReadElapsedClock()
  • FS_GetFileProperties()
  • FS_SendFile()

The functions you must call are:


This function is called by the web server to figure out if a connection has typed out.  It returns the number of seconds that have passed.  This does not have to start a 0 but can.

If you are have a real time clock you can return it's value (the seconds anyway).

If your system does not have a real time clock returning a timer that starts at 0 on boot work fine.

So long as this value continues to go up every second BittyHTTP is happy.

You can have this always return 0, however this will disable time outs and a badly behaving browser could lock out your web server).

So for example:

t_ElapsedTime ReadElapsedClock(void)
   return (uint32_t)time(NULL);


This function is called when the web server gets a request for a file.  This first argument to the function is the filename that was requested.  This is a standard C string so you can do things like strcmp() on it.  Note that the filename includes the path part as well.

The seconds argument is a WSPageProp structure.  You must fill this in if you want to serve this page.

So for example if you support the filename "Example.html" you might use code like this:

bool FS_GetFileProperties(const char *Filename,struct WSPageProp *PageProp)
      return true;
      return false;

The Cookies, Gets, and Posts pointers are used if your page supports one or more of them.

The FileID is where you signal to the FS_SendFile() function what file it should send.  This is large enough to store a pointer.

The reason sending a file is split into 2 functions is because FS_GetFileProperties() is called before all the headers have been processed.  The buffer used for the filename is the same buffer used to process headers.  By the time all the headers have been processed the filename has been lost.


This function is called after all the headers are processed and the system is ready to send the requested file.  You take the FileID you setup in FS_GetFileProperties() and use it to decide what file to send.

void FS_SendFile(struct WebServer *Web,uintptr_t FileID)
      WS_WriteWhole(Web,"Hello World",11);

In this case we handle the file directly in FS_SendFile() instead of calling a different function.  We just check the FileID is 1 and call WS_WriteWhole() to send "Hello World"


This function is from the POSIX socket file SocketsCon.c file.  It readies the sockets for use.  If you are using your own sockets you don't need this function.


This function init's the web servers state machines and other data.


This function tells BittyHTTP to start listening for incoming connections on the provided port.  Note that it will not actually accept the incoming connection unless WS_Tick() is being called.


This function needs to be called regularly for the BittyHTTP state machine to accept connections, read data, process headers, and call backs FS_GetFileProperties() and FS_SendFile().


This shuts down the web server.  It stops it from listening and closes all the sockets.


This function is from the POSIX socket file SocketsCon.c file.  It frees any resources that the socket connection system was using.  If you are using your own sockets you don't...

Read more »

  • 1
    Download BittyHTTP

    Download the latest version from

  • 2
    Uncompress the tar.gz

    The examples are made for Linux but should work on any POSIX OS.

    tar -xzf BittyHTTP1_4.tar.gz
  • 3
    Enter the Bitty HTTP source directory
    cd BittyHTTP/src

View all 6 instructions

Enjoy this project?



Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates