Hi Roel,

Roel Janssen <r...@gnu.org> skribis:

> I'd like to implement a web server using the (web server) module, but
> allow for “streaming” results.  The way I image this would look like,
> is something like this:
>
> (define (request-handler request body)
>   (values '((content-type . (text/plain)))
>           ;; This function can build its response by writing to
>           ;; ‘port’, rather than to return the whole body as a
>           ;; string.
>           (lambda (port)
>             (format port "Hello world!"))))
>
> (run-server request-handler)
>
> Is this possible with the (web server) module?  If so, how?
> If not, what would be a good starting point to implement this?

As discussed on IRC a few days ago, this is not really possible.  ‘guix
publish’ works around it by providing a custom implementation of the
‘write’ method of the HTTP server and having handlers provide a “fake”
body to be interpreted by this ‘write’ implementation:

  https://git.savannah.gnu.org/cgit/guix.git/tree/guix/scripts/publish.scm#n690
  https://git.savannah.gnu.org/cgit/guix.git/tree/guix/scripts/publish.scm#n522

I reported this limitation of (web server) at
<https://issues.guix.info/issue/21093>.

Thanks,
Ludo’.


Reply via email to