joaotavora / snooze

Common Lisp RESTful web development
207 stars 23 forks source link

if payload's bytes, don't wrap in a list for clack #32

Open strawhatguy opened 2 years ago

strawhatguy commented 2 years ago

The payload for clack/woo can be a pathname, a list of strings, AND a vector of bytes; the latter allows web server to generate bytes (image, pdf, etc) without needing it to be a file on disk.

Before, returning a vector would complain about being the wrong type.

e.g. something like this now works, where it didn't before - find-static-file just returns a pathname of a png:

(snooze:defresource img (verb content-type name)
  (:route (:get :image/png filename)
          (let ((realpath (format nil "~a.png" (string-downcase filename))))
            (alexandria:read-file-into-byte-vector (find-static-file "img" realpath)))))