fukamachi / ningle

Super micro framework for Common Lisp
http://8arrow.org/ningle/
273 stars 25 forks source link

Serving arbitrary binary data #20

Closed thiru closed 7 years ago

thiru commented 7 years ago

Hi there, great work on this project!

What would be the best way to serve an arbitrary (binary) file that is outside the static files root directory? E.g. say the request is "localhost/download/path/to/file.pdf".

resttime commented 7 years ago

I'm not too sure but this might be the relevant documentation, look for the Delayed Response and Streaming Body topic under https://github.com/fukamachi/lack . I forgot the syntax but I do remember doing something in ningle with this.

At least I think that's one way by using that after setting the *RESPONSE* to content-type application/octet-stream.

(setf (lack.response:response-headers *response*)
        (append (lack.response:response-headers *response*)
                     (list :content-type "application/octect-stream")))

I'm not sure what you want is a good idea though for security reasons since I'm under the impression most web dev likes to keep what's "public" separate from the "private".

thiru commented 7 years ago

Thanks for the quick response @resttime, much appreciated!

I noticed the Lack readme says it's possible to return a pathname as the response body. This seems to work and I can point it at any arbitrary path in the file-system.

I know this sounds like a crazy thing to do but the nature of the app I'm building is to serve as a sort of web-based file browser.

resttime commented 7 years ago

No problem @thiru. You caught me while I was submitting an issue so I thought I'd help! :)

Can't believe I forgot about pathnames though because the static middleware basically works by returning pathnames that match a regexp. My solution would be overkill for your use case and better for something like a shoutcast/icecast music streamer.