ro...@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 via email to