Hi!
A simple convenience function for serving static files with TBNL.
Example:
(create-static-file-dispatcher-and-handler "/css/main.css" #P"css/main.css" "text/css")
Maybe someone finds a better name and documentation. :-)
(defun create-static-file-dispatcher-and-handler (uri path content-type) "Creates a dispatch function which will dispatch to a handler function which emits the file PATH with CONTENT-TYPE if the URI matches the SCRIPT-NAME of the request." (let ((buf (make-array 8192 :element-type #-:tbnl-bivalent-streams 'character #+:tbnl-bivalent-streams '(unsigned-byte 8)))) (let ((handler #'(lambda () (setf (content-type) content-type) (with-output-to-string (str) (with-open-file (file path :direction :input #+:tbnl-bivalent-streams :element-type #+:tbnl-bivalent-streams '(unsigned-byte 8)) (do ((pos (read-sequence buf file) (read-sequence buf file))) ((zerop pos)) (write-sequence buf str :end pos))))))) #'(lambda (request) (when (equal (script-name request) uri) handler)))))
Regards, Stefan
On Tue, 20 Jul 2004 22:56:21 +0200, Stefan Scholl stesch@no-spoon.de wrote:
A simple convenience function for serving static files with TBNL.
Thanks, it's in 0.2.5 now.