[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
MIME type guessing module
From: |
David Thompson |
Subject: |
MIME type guessing module |
Date: |
Wed, 31 Dec 2014 11:36:22 -0500 |
User-agent: |
Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) |
Hello Guile hackers,
Recently I've taken to writing simple web servers in Guile. Each time I
write one I wish that core Guile came with a procedure to guess the mime
type of a file. Such a procedure would be very useful when serving
arbitrary static files from disk.
However, I can't figure out the best way to implement it. Here are 3
possible ways of guessing a MIME type:
1) Use a lookup table that maps file extensions to MIME types. This is
the simplest method as it would only test file extensions. Python does
this, see: <https://docs.python.org/2/library/mimetypes.html>
2) Use pipes to read the output of the 'file' utility. The guessing
will be more accurate because 'file' inspects a file's contents to make
better guesses.
3) Use the FFI to call libmagic. Same benefits as above, but better
because we can use the FFI instead of subprocesses and pipes.
2 and 3 both have the disadvantage of requiring an additional
dependency, which seems hard to justify for such a minor feature.
I wrote a simple static file server (inspired by Python's
SimpleHTTPServer) that I would like to contribute once this blocker is
resolved.
Thoughts? Would this be useful at all?
Thanks,
--
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate
- MIME type guessing module,
David Thompson <=