unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Roel Janssen <roel@gnu.org>
To: Amirouche Boubekki <amirouche@hypermove.net>
Cc: guile-user@gnu.org,
	guile-user <guile-user-bounces+amirouche=hypermove.net@gnu.org>
Subject: Re: Streaming responses with Guile's web modules
Date: Wed, 19 Sep 2018 10:47:04 +0200	[thread overview]
Message-ID: <87va71euwn.fsf@gnu.org> (raw)
In-Reply-To: <9d7057dece124a045eb5e09e1b1799da@hypermove.net>


Amirouche Boubekki <amirouche@hypermove.net> writes:

> On 2018-09-18 21:42, Roel Janssen wrote:
>> Dear Guilers,
>>
>> I'd like to implement a web server using the (web server) module, but
>> allow for “streaming” results.  The way I imagine 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?
>
> What you describe is exactly how it works. The second value can
> be a bytevector, #f or a procedure that takes a port as argument.
>
> Here is an example use [0] and here is the code [1]
>
> [0]
> https://framagit.org/a-guile-mind/culturia.next/blob/master/culturia/web/helpers.scm#L34
> [1]
> https://git.savannah.gnu.org/cgit/guile.git/tree/module/web/server.scm#n198
>
> Regards

Thanks for your quick and elaborate reply!  I didn't realize that in
writing the example I had written a working example.

Looking at memory usage, it looks as if it puts all bytes produced by
that function into memory at once before sending the HTTP response over
the network.  Is that observation correct?  If so, can it be avoided?

Kind regards,
Roel Janssen



  reply	other threads:[~2018-09-19  8:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-18 19:42 Streaming responses with Guile's web modules Roel Janssen
2018-09-18 20:08 ` Amirouche Boubekki
2018-09-19  8:47   ` Roel Janssen [this message]
2018-09-19 15:50     ` Roel Janssen
2018-09-22 13:54     ` Roel Janssen
2018-09-23 13:20 ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87va71euwn.fsf@gnu.org \
    --to=roel@gnu.org \
    --cc=amirouche@hypermove.net \
    --cc=guile-user-bounces+amirouche=hypermove.net@gnu.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).