From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Neil Jerram Newsgroups: gmane.lisp.guile.user Subject: Re: Serving files with guile web server Date: Sat, 19 Mar 2011 18:17:32 +0000 Message-ID: <87aagrrn43.fsf@ossau.uklinux.net> References: <9838.187.147.43.113.1300318403.squirrel@lavabit.com> <58164.187.147.43.113.1300373729.squirrel@lavabit.com> <874o6z97gg.fsf@ossau.uklinux.net> <18101.189.215.48.232.1300553233.squirrel@lavabit.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1300558673 25326 80.91.229.12 (19 Mar 2011 18:17:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 19 Mar 2011 18:17:53 +0000 (UTC) Cc: guile-user@gnu.org To: romel@lavabit.com Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Mar 19 19:17:49 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q10ii-00040S-ML for guile-user@m.gmane.org; Sat, 19 Mar 2011 19:17:48 +0100 Original-Received: from localhost ([127.0.0.1]:35548 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q10ii-0000RE-0z for guile-user@m.gmane.org; Sat, 19 Mar 2011 14:17:48 -0400 Original-Received: from [140.186.70.92] (port=44948 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q10if-0000R9-2L for guile-user@gnu.org; Sat, 19 Mar 2011 14:17:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q10id-0005GH-IA for guile-user@gnu.org; Sat, 19 Mar 2011 14:17:44 -0400 Original-Received: from mail3.uklinux.net ([80.84.72.33]:50182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q10id-0005G5-Ax for guile-user@gnu.org; Sat, 19 Mar 2011 14:17:43 -0400 Original-Received: from arudy (unknown [78.149.206.140]) by mail3.uklinux.net (Postfix) with ESMTP id 9C9BC1F66B9; Sat, 19 Mar 2011 18:17:35 +0000 (GMT) Original-Received: from neil-laptop (neil-laptop [192.168.11.7]) by arudy (Postfix) with ESMTP id 37BEB3801E; Sat, 19 Mar 2011 18:17:33 +0000 (GMT) In-Reply-To: <18101.189.215.48.232.1300553233.squirrel@lavabit.com> (romel@lavabit.com's message of "Sat, 19 Mar 2011 12:47:13 -0400 (EDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 80.84.72.33 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8545 Archived-At: romel@lavabit.com writes: > So far I have been able to serve text files and images, it should work > with any mime-type now, but I have not test it yet. > > Here is the piece of code that handles files for the curious: > > (let ((file-path (public-file-path path))) > (if (file-exists? file-path) > (let* ((mime-type (mime-type-ref file-path)) > (mime-type-symbol (mime-type-symbol mime-type))) > (if (text-mime-type? mime-type) > (values > `((content-type . (,mime-type-symbol))) > (lambda (out-port) > (call-with-input-file file-path > (lambda (in-port) > (display (read-delimited "" in-port) > out-port))))) > (values > `((content-type . (,mime-type-symbol))) > (call-with-input-file file-path > (lambda (in-port) > (get-bytevector-all in-port)))))) > (not-found request))) > > I hope it's readable :-) Certainly, it looks good. Where does mime-type-ref come from, though? Perhaps that could be wrapped up as `static-file-response' (or a better name if you can think of one) and added to (web server). Regards, Neil