From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Roel Janssen Newsgroups: gmane.lisp.guile.user Subject: Re: Streaming responses with Guile's web modules Date: Wed, 19 Sep 2018 10:47:04 +0200 Message-ID: <87va71euwn.fsf@gnu.org> References: <87in32y4m0.fsf@gnu.org> <9d7057dece124a045eb5e09e1b1799da@hypermove.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1537346749 23208 195.159.176.226 (19 Sep 2018 08:45:49 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Sep 2018 08:45:49 +0000 (UTC) User-Agent: mu4e 1.0; emacs 26.1 Cc: guile-user@gnu.org, guile-user To: Amirouche Boubekki Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Sep 19 10:45:45 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g2Y7A-0005rz-0G for guile-user@m.gmane.org; Wed, 19 Sep 2018 10:45:40 +0200 Original-Received: from localhost ([::1]:44273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2Y9G-0003x3-Fz for guile-user@m.gmane.org; Wed, 19 Sep 2018 04:47:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52571) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2Y8o-0003ng-3r for guile-user@gnu.org; Wed, 19 Sep 2018 04:47:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2Y8n-000253-AV for guile-user@gnu.org; Wed, 19 Sep 2018 04:47:22 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:37428) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2Y8d-0001xo-KN; Wed, 19 Sep 2018 04:47:11 -0400 Original-Received: from [143.121.239.252] (port=41368 helo=yellowstone) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1g2Y8d-0002F9-3m; Wed, 19 Sep 2018 04:47:11 -0400 In-reply-to: <9d7057dece124a045eb5e09e1b1799da@hypermove.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14887 Archived-At: Amirouche Boubekki 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 =E2=80=9Cstreaming=E2=80=9D results. The way I imagine this w= ould 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 >> ;; =E2=80=98port=E2=80=99, rather than to return the whole bod= y 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#n1= 98 > > 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