site

source files for beau's website
git clone https://git.beauhilton.com/site.git
Log | Files | Refs

mime.md (2773B)


      1 # fix MIME Types to unbreak RSS feeds served by OpenBSD's httpd(8)
      2 
      3 
      4 ## RSS is life - but mine was broken
      5 
      6 
      7 As of today (2022-11-13) my website lives on 
      8 an OpenBSD server hosted at [vultr](https://vultr.com).
      9 
     10 It's great, delightfully simple and low-resource,
     11 robust, extendable, low-maintenance.
     12 
     13 I've been getting back into RSS lately.
     14 Turns out, my own RSS feed was broken.
     15 I knew it was janky, but would have had no idea how broken it was
     16 if not for the great folks
     17 on the [datasette](https://datasette.io) Discord,
     18 one of whom reached out to let me know my RSS link wasn't working.
     19 
     20 This could not stand!
     21 
     22 I've been meaning to fix my RSS feed anyway,
     23 and now I had a good reason.
     24 
     25 
     26 ## fixing the file itself
     27 
     28 
     29 I ended up tearing out my previous RSS solution, [`rssg`](https://romanzolotarev.com/rssg.html),which is great but made some assumptions about my site's layout that aren't true.
     30 I could have rewritten the script, 
     31 but I'm lazy and a little strapped for time,
     32 so I ended up replacing it with a hand-written RSS file.
     33 
     34 (The RSS spec is easy enough to write by hand,
     35 a little copy-paste and replace to add a new article - 
     36 at some point I'll probably migrate to `hugo` or similar
     37 and hand off the feed creation to a more flexible script,
     38 but for now this works).
     39 
     40 After I was certain the file format was fine and had the info I wanted,
     41 I thought I was good.
     42 
     43 
     44 ## fixing the MIME Type
     45 
     46 
     47 The kind soul who reached out to let me know the RSS feed was malformed 
     48 reached out again to let me know he was now getting a MIME Type error.
     49 
     50 My feedreader of choice, `newsboat`, 
     51 is very forgiving of what it accepts, 
     52 and didn't throw any errors when I tested it.
     53 `FreshRSS`, on the other hand, is more strict, 
     54 and the feed would fail even though the file itself was fine.
     55 
     56 I looked into it, and found out that `httpd(8)`
     57 only supports a handful of MIME Types by default,
     58 so my server was sending out `application/octet-stream`
     59 (a generic type) instead of the `rss+xml` type,
     60 and it was confusing the feedreader.
     61 
     62 
     63 ## add all the types
     64 
     65 
     66 Thank goodness, and as usual in OpenBSD, 
     67 there's a very easy way to add all the relevant types one might need.
     68 
     69 OpenBSD has an internal MIME declaration file you can link to from within `httpd.conf(5)`.
     70 
     71 Here's the relevant bit, just chuck this on the end of the conf file:
     72 
     73 ```shell
     74 
     75 types {
     76     include "/usr/share/misc/mime.types"
     77 }
     78 
     79 ```
     80 
     81 And reload `httpd(8)`.
     82 
     83 
     84 ## great success
     85 
     86 
     87 Much thanks to my new friend on the Datasette Discord, 
     88 the fantastic OpenBSD documentation,
     89 as always,
     90 and [lambda.cx](https://blog.lambda.cx/posts/openbsd-httpd-mime-types/)
     91 for writing a post almost identical to mine 
     92 (except that his had nothing to do with RSS - 
     93 he was fixing PDF serving, 
     94 which should now be fixed on my site as well).
     95