From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Thompson Newsgroups: gmane.lisp.guile.devel Subject: MIME type guessing module Date: Wed, 31 Dec 2014 11:36:22 -0500 Message-ID: <87oaqjlqt5.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1420043795 21449 80.91.229.3 (31 Dec 2014 16:36:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 31 Dec 2014 16:36:35 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Wed Dec 31 17:36:30 2014 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Y6MG5-00009S-2x for guile-devel@m.gmane.org; Wed, 31 Dec 2014 17:36:29 +0100 Original-Received: from localhost ([::1]:40652 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y6MG4-0001rM-DT for guile-devel@m.gmane.org; Wed, 31 Dec 2014 11:36:28 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y6MG0-0001rH-QN for guile-devel@gnu.org; Wed, 31 Dec 2014 11:36:25 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y6MFz-0005fP-KL for guile-devel@gnu.org; Wed, 31 Dec 2014 11:36:24 -0500 Original-Received: from mail.fsf.org ([208.118.235.13]:51477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y6MFz-0005fL-I8 for guile-devel@gnu.org; Wed, 31 Dec 2014 11:36:23 -0500 Original-Received: from 209-6-40-86.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.40.86]:40253 helo=izanagi) by mail.fsf.org with esmtpsa (TLS-1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1Y6MFz-0003rm-BK for guile-devel@gnu.org; Wed, 31 Dec 2014 11:36:23 -0500 User-Agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) X-detected-operating-system: by mail.fsf.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.13 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:17629 Archived-At: 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: 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