From 37b35d7c7b4797591be767861e3dbbecb717da2d Mon Sep 17 00:00:00 2001 From: Dante Catalfamo Date: Sat, 15 Aug 2020 02:04:04 -0400 Subject: openbsd-mime: Add OpenBSD httpd mime types article and image --- content/posts/openbsd-httpd-mime-types/cover.png | Bin 0 -> 150647 bytes content/posts/openbsd-httpd-mime-types/index.org | 72 +++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 content/posts/openbsd-httpd-mime-types/cover.png create mode 100644 content/posts/openbsd-httpd-mime-types/index.org diff --git a/content/posts/openbsd-httpd-mime-types/cover.png b/content/posts/openbsd-httpd-mime-types/cover.png new file mode 100644 index 0000000..755b476 Binary files /dev/null and b/content/posts/openbsd-httpd-mime-types/cover.png differ diff --git a/content/posts/openbsd-httpd-mime-types/index.org b/content/posts/openbsd-httpd-mime-types/index.org new file mode 100644 index 0000000..7015c2d --- /dev/null +++ b/content/posts/openbsd-httpd-mime-types/index.org @@ -0,0 +1,72 @@ +#+TITLE: OpenBSD httpd MIME Types +#+DATE: 2020-08-15T01:49:22-04:00 +#+DRAFT: true +#+DESCRIPTION: How to get OpenBSD httpd to return the proper MIME types for files +#+TAGS[]: openbsd httpd +#+KEYWORDS[]: openbsd httpd +#+SLUG: +#+SUMMARY: + +#+ATTR_HTML: :title OpenBSD httpd MIME type recognition +#+ATTR_HTML: :alt OpenBSD httpd MIME type recognition +[[file:cover.png]] + +On openbsd's httpd, there are only a select few mime types that are +recognized by default. according to [[https://man.openbsd.org/httpd.conf.5][=httpd.conf(5)=]], those types are: +=ext/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. + +this is ok for most static hosting situations, but can be challenging +for some common attachment types. for example, i recently made a blog +post that had an attached pdf. normally web browsers open pdf files in +the browser's pdf viewer, but since it was being returned with the +mime-type =application/octet-stream=, the browser decided to download +it instead of openning it directly. this isn't a tragedy, but it can +be annoying and interrupt the flow of the user's experience. + +the solution to this is to include the =application/pdf= mime type in +the [[https://man.openbsd.org/httpd.conf.5#types][=types=]] block in your =httpd.conf=. there are two ways to go about +this. either by manually defining the type you require, or including +the system's built-in mime type database. + +using the first method you would include a types block that defines +all of the mime types you require. this types block can go anywhere +outside of a server declaration. + +the types are defined in the format of =type/subtype name [name ...]= + +#+begin_src +types { + text/css css + text/html html htm + text/plain txt + image/gif gif + image/jpeg jpeg jpg + image/png png + application/javascript js + application/pdf pdf +} +#+end_src + +the second method, including the system's built-in mime types +database, is simpler if you need to support proper mime types for a +larger number of files, and don't want to go through the process of +writing them all in by hand. this is done by defining a similar types +block, but instead of writing in type data, you us the [[https://man.openbsd.org/httpd.conf.5#include][=include=]] +directive. openbsd's mime type definitions are stored in +=/usr/share/misc/mime.types=. + +#+BEGIN_SRC +types { + include "/usr/share/misc/mime.types" +} +#+END_SRC + +After editing the configuration file, all you have to do is reload +httpd, and it should begin recognizing file types properly. + +#+BEGIN_SRC shell +doas rcctl reload httpd +#+END_SRC -- cgit v1.2.3