nvhttpd

Introduction

nvhttpd was initially written over Thanksgiving, 2024 and the following day. Since then, I’ve rearranged some things, added a feature or two and fixed some bugs. It became stable enough for me to go live with it the week before Christmas, 2024. Initially, I thought I’d slap together a server in NodeJS and use that to serve this site. Then I thought it would be interesting to write an HTTP server from scratch in C, so that’s what I did.

Features

nvhttpd has a limited feature set. It’s meant to be simple, fast, light on resources and reliable. To that end, it only serves static content. You give it an HTML directory, it loads it into a cache at startup and serves all requests from the cache. The cache can be reloaded manually by sending a SIGUSR1 to the server.

All requests are handled in their own thread. I don’t use a thread pool, I just create a new thread every time an accept() returns a request. The request is parsed and then an appropriate response is generated then the thread terminates.

The server can be configured at runtime to use SSL. It won’t listen on multiple ports simultaneously, so I stick with SSL for this site. That leaves port 80 open for certbot to renew the SSL certificate automatically every day.

With debugging info stripped, the binary is about 60K in size. It can be compiled to produce prodigious debug log output and/or gdb debug info, of course.

References

HTTP/1.1

HTTP/1.0

To Do

  • At some point, I want to add gzip compression support.
  • SSL usage needs to be cleaned up.

Last modified on 2024-12-23