Hacker News new | ask | show | jobs
by lipanski 1869 days ago
My favourite is thttpd [1] which is super tiny, battle-tested and actually meant for the job (and only this job). It's available as a package on most Linux distros.

Serving a static folder `/static` on port `3000` as user `static-user` and with cache headers set to 60 seconds would go like this:

  thttpd -D -h 0.0.0.0 -p 3000 -d /static -u static-user -l - -M 60
Even if you've got Python lying around on every Ubuntu server, I still don't get why you wouldn't use something leaner to serve your static files, as long as it's easy to install/configure. Same goes for most of the runtimes in that list.

[1] https://www.acme.com/software/thttpd/

4 comments

Because the point is that I want a webserver up now. If I was running something long-term I would just use Caddy anyway.
Yeah, I want a HTTP server up because I need an actual server to test my web app or because I want to send a large file to someone on my local network and don't want to guide them through setting up smb/rsync/whatever and just want to give them a URL.

I don't particularly care about what's least likely to fall over under sustained load or is suitable security wise to expose to the internet, because it's not going to have to deal with either of these things. Being "already installed" on the other hand is a big selling point.

> My favourite is thttpd [1] which is super tiny, battle-tested and actually meant for the job (and only this job). It's available as a package on most Linux distros.

Surprising not on Debian or Ubuntu AFAICT:

* https://packages.debian.org/search?keywords=thttpd

Though it does seem to have this from the same author:

* https://packages.debian.org/search?keywords=mini-httpd

* http://www.acme.com/software/mini_httpd/

There are times that I want to run Let's Encrypt that's not a full-time web server (SMTP, IMAP, etc), and it would be handy to spin up something ad hoc on tcp/80 to do the verification step and then stop it right after.

thttpd has one cool cat badge icon but have you seen its critical path http parsing code?

        /* Read the MIME headers. */
        while ( ( buf = bufgets( hc ) ) != (char*) 0 )
            {
            if ( buf[0] == '\0' )
                break;
            if ( strncasecmp( buf, "Referer:", 8 ) == 0 )
                {
                cp = &buf[8];
                cp += strspn( cp, " \t" );
                hc->referrer = cp;
                }
            else if ( strncasecmp( buf, "Referrer:", 9 ) == 0 )
                {
                cp = &buf[9];
                cp += strspn( cp, " \t" );
                hc->referrer = cp;
                }
            else if ( strncasecmp( buf, "User-Agent:", 11 ) == 0 )
                {
                cp = &buf[11];
                cp += strspn( cp, " \t" );
                hc->useragent = cp;
                }
            else if ( strncasecmp( buf, "Host:", 5 ) == 0 )
                {
                cp = &buf[5];
                cp += strspn( cp, " \t" );
                hc->hdrhost = cp;
Use perfect hash tables for known http headers, because they're perfect.