Hi Nala, Nala Ginrut <nalagin...@gmail.com> writes:
> I'm trying to handle static file with our sendfile, but I realized it's > impossible to call it in the handler of run-server. > Although sanitize-response supports procedure as body, it never let me > use sendfile at any chance, because the final writing operation should > be delayed to server-impl-write. If I do it in advanced (in > sanitize-response), the body will appear before the http header, which > is wrong way. > > My suggestion is to support thunk as body, the thunk included body > writing operation, and sanitize-response will pass it to the next step > without any cooking. When server-impl-write detected it's a thunk, it'll > call it directly to write the body rather than calling > write-response-body. > > Of course, in this way, users have to pass Content-Length manually in > build-response. Consider the size of file will be confirmed when calling > sendfile, it's easy to do that. > > In short, my approach is some kind of lazy evaluation for body handling. > > I can format a patch if it's agreed. > > Comments? I'm currently writing a web application using Guile's built-in HTTP server. To serve static files, I build a response like: (values `((content-type . (text/css))) (call-with-input-file file-name get-bytevector-all)) Since the response body can be a string, bytevector, or lambda, I tried using sendfile: (values `((content-type . (text/css))) (lambda (output) (call-with-input-file file-name (lambda (input) (sendfile output input file-size))))) However, it didn't work because 'output' is a string port, but sendfile requires file ports. Does your proposal give us access to a file port that we can write to? I'm still learning to use Guile's HTTP modules and serving static files was something that confused me for awhile. -- David Thompson Web Developer - Free Software Foundation - http://fsf.org GPG Key: 0FF1D807 Support the FSF: https://fsf.org/donate