OpenBSD httpd MIME types and feeds

Earlier today I got an email from Yahor. He subscribes to one of this site's feeds, but had seen no new updates in his feed reader since the middle of November.

As if letting me know wasn't enough, he was kind enough to share some info to help me debug the problem as well. When he entered the URL to my Posts feed into FreshRSS, he got the following error message:

A feed could not be found at https://lars-christian.com/posts/feed.xml; the status code is 200 and content-type is application/octet-stream [https://lars-christian.com/posts/feed.xml]

While the feed still validated, the W3C Feed Validator gave a similar warning:

Screenshot from w3c's feed validator stating that the feed is valid, but warning that "Feeds should not be served with the "application/octet-stream" media type"

At first I didn't quite get what caused this. The feed validated without any warnings when I first rolled out my custom static site generator. Did I include some content that the parser messed up somehow?

Then I connected the dots. I moved the site to a new host back in November. Must be related to that, I concluded. Some quick research guided me to this post stating that:

On OpenBSD's httpd, there are only a select few MIME types that are recognized by default. According to httpd.conf(5), those types are: text/css, text/html, text/plain, image/gif, image/png, image/jpeg, image/svg+xml, and application/javascript. Everything else is said to be of type application/octet-stream by default

There we have! The httpd web server doesn't specify a MIME type for feeds out of the box. Instead, it simply defaults to "application/octet-stream".

Apparently this is not a big deal for all feed readers. Reeder Classic, which I use daily (and to see that my feeds are working) never objected after the switch. But I want "the widest range of interoperability" so I needed to sort this out. The blog post I linked to above suggests using OpenBSD's default MIME type definitions by updating the httpd.conf file to include the following:

types {
    include "/usr/share/misc/mime.types"
}

My first stumbling block was figuring out where to include this. I pasted it (I actually typed it by hand because I still haven't figured out how to paste something in Vi ^_^) at the very top and tested my configuration by typing httpd -n and it seemed OK.

Unfortunately, this didn't solve my problem. My feed files are served as .xml files, and the default MIME type for the xml extension is text/xml. Since my feed files follow the Atom specification, I needed to do one of two things:

  • Switch my feed files from .xml to .atom file extensions, or
  • Change the MIME type associated with the .xml file extension

I decided to go for the latter option. Why? Because the former would involve more work. As editing the file referenced above is not a good solution (I tried and got a warning that I shouldn't do it), I simply added it manually to the types definition in my httpd.conf file. Like so:

types {
    application/atom+xml        atom xml
}

Of course, this caused some added issues. By outright defining types in the conf file, it seems the default type associations are no longer being served. Which meant that, while the atom feed was finally being served with the correct type, the plain HTML files that make up my website weren't.

Luckily I noticed quickly, and added the defaults (still by typing them by hand, so there are probably some typos in there) to the configuration file. It now looks like this:

types {
    application/atom+xml        atom xml
    text/html                   html htm
    text/css                    css
    text/plain                  txt
    image/gif                   gif
    image/png                   png
    image/jpeg                  jpeg jpg
    image/svg+xml               svg
    application/javascript      js
}

I think that everything should be working fine again now. If something looks strange, please let me know.

And thanks again to Yahor for letting me know about his troubles with the feed. wanted to pay it forward by sharing what I learned here, on the off chance that someone else stumbles across a similar problem with their own httpd setup on OpenBSD.