Send the correct mime type when serving documents

...and for PDFs instruct the browser to display them.

For file formats such as PDFs and Images, the user's browser can usually display the downloaded file without asking the user to save it first. For this to happen, you need to send the correct content type e.g. 'application/pdf'. Python has a mimetypes module in stdlib which can guess these based on the filename. I use this and fall back to the generic 'application/octet-stream' if it cannot be guessed.

I have special cased PDF as not being an attachment as this seems to be what most of the clients at our company want to happen on their sites.