Index | Thread | Search

From:
Adam Mullins <alm@alm4x.com>
Subject:
add support to httpd for serving static brotli encoded files
To:
tech@openbsd.org
Date:
Mon, 23 Feb 2026 21:31:24 -0500

Download raw body.

Thread
Hello. This is my first time contributing to a free software project. 
Feel free to let me know if I have made any mistakes or missed anything. 
Sorry for the long email, but I wanted to cover everything.

Currently httpd has the ability to preferentially serve gzip encoded 
static files, but not brotli encoded files. This patch adds the 
brotli-static option to httpd, allowing it to serve .br files to 
clients. Brotli offers 10-20% better compression than gzip for common 
web file types.

With this patch, when brotli-static is set in httpd.conf, httpd will 
serve a *.br file if the client has signaled it will accept it, and the 
connection is inside of TLS, and the *.br version is no older than the 
*.gz and unencoded file. Failing that, it will try to serve the gzip 
version under the same constraints, minus the TLS requirement. Finally, 
it defaults to serving the unencoded file.

Changes:
- Update httpd.conf.5 to explain the new option.
- Add rules and logic for parsing httpd.conf to parse.y.
- Add SRVFLAG_BROTLI_STATIC to httpd.h.
- Migrate encoded file selection logic out of 
server_file.c:server_file_access() to a helper
   static function, and adds logic to select *.br files if they exist.

I was uncertain about a couple of things.

First, I #define'd SRVFLAG_BROTLI_STATIC to 0x10000000. This particular 
number was skipped by the other flags (ie, the flags went from 0x08... 
to 0x40...). I'm not sure if this constant is being avoided for some 
reason, but everything seems to be working okay. Also, with this 
addition we are out of possible 32 bit combinations unless I am missing 
something.

Second, I tried a few approaches to the selection logic flow, but I 
couldn't get it any more compact. It was taking up a lot of space in the 
original function, so I migrated it to a helper. I only noticed a few 
others like this in the project, so I'm not sure if this idiomatic. 
Also, while my additions check the return of libc calls like fstat() and 
snprintf() for errors, it _does not_ check that all passed in pointers 
are non-NULL. This seems reasonable to me given that it is a file-local 
helper, called from only one function, and that caller likewise does not 
check its arguments (ie server_file_access does not verify `struct 
client *clt` is non-NULL before dereferencing it).