unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: David Thompson <dthompson2@worcester.edu>
To: guile-devel@gnu.org
Subject: MIME type guessing module
Date: Wed, 31 Dec 2014 11:36:22 -0500	[thread overview]
Message-ID: <87oaqjlqt5.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> (raw)

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



             reply	other threads:[~2014-12-31 16:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-31 16:36 David Thompson [this message]
2015-01-01  0:14 ` MIME type guessing module Mike Gerwitz
2015-01-02 15:33 ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oaqjlqt5.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me \
    --to=dthompson2@worcester.edu \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).