unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Neil Jerram <neil@ossau.uklinux.net>
To: romel@lavabit.com
Cc: guile-user@gnu.org
Subject: Re: Serving files with guile web server
Date: Sat, 19 Mar 2011 18:17:32 +0000	[thread overview]
Message-ID: <87aagrrn43.fsf@ossau.uklinux.net> (raw)
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)")

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



  reply	other threads:[~2011-03-19 18:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16 23:33 Serving files with guile web server romel
2011-03-17 14:55 ` romel
2011-03-19  2:20   ` Neil Jerram
2011-03-19 16:47     ` romel
2011-03-19 18:17       ` Neil Jerram [this message]
2011-03-19 22:23         ` romel
2011-03-31 14:44       ` Andy Wingo
2011-03-22  8:51     ` Thien-Thi Nguyen
2011-03-31 14:23       ` Andy Wingo
2011-03-31 15:09         ` Andy Wingo

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=87aagrrn43.fsf@ossau.uklinux.net \
    --to=neil@ossau.uklinux.net \
    --cc=guile-user@gnu.org \
    --cc=romel@lavabit.com \
    /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).