$ cat ~nutts/blog/*.md

Configuring a UTF-8 charset in OpenBSD's httpd

I discovered that OpenBSD's httpd web server does not set a default character set of UTF-8, like one might sensibly assume these days.

Viewing the raw twtxt.txt file for my status page in a web browser, showed all the emoji and star characters as mangled; the default charset seems to be ISO-8859-1.

There's no mention of it in OpenBSD's httpd.conf(5) man page, nor in the OpenBSD Handbook. In the end I found a single reddit post, and a blog post titled Web server setup with OpenBSD, which held the correct solution. My "dumb assistant" Claude had no idea about the correct format required.

Turns out that to change the character set to UTF-8, you need some rather strange quoting in your httpd.conf to avoid a "syntax error":

types {
    include "/usr/share/misc/mime.types"
    "text"/"plain; charset=utf-8"            txt
    "text"/"markdown; charset=utf-8"         md
    "text"/"html; charset=utf-8"             html htm shtml
    "text"/"css; charset=utf-8"              css
    "application"/"json; charset=utf-8"      json
}

I also added text/markdown which isn't included in the mime.types file. It seems it was only ratified as RFC 7763 in 2016.

Funnily enough, I later found a twtxt conversation complaining about this very problem, and pointing to a mailing list archive with the same solution.

#openbsd #tech