[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Serving files with guile web server
From: |
Neil Jerram |
Subject: |
Re: Serving files with guile web server |
Date: |
Sat, 19 Mar 2011 18:17:32 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
address@hidden 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