From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Daniel_Mei=DFner?= Newsgroups: gmane.lisp.guile.user Subject: Re: Operate upon POST request with Guile webserver Date: Fri, 19 Aug 2022 13:00:41 +0200 Message-ID: References: <828eadbc-c2bf-c4ab-0833-96c55011d36c@firemail.cc> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24783"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Aug 19 13:23:37 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oP06C-0006FL-OY for guile-user@m.gmane-mx.org; Fri, 19 Aug 2022 13:23:36 +0200 Original-Received: from localhost ([::1]:44252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oP06B-0000xy-Aj for guile-user@m.gmane-mx.org; Fri, 19 Aug 2022 07:23:35 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOzkU-0002GX-Gh for guile-user@gnu.org; Fri, 19 Aug 2022 07:01:12 -0400 Original-Received: from out3.mail.ruhr-uni-bochum.de ([134.147.53.155]:31510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOzkL-0001PL-06 for guile-user@gnu.org; Fri, 19 Aug 2022 07:01:09 -0400 Original-Received: from mx3.mail.ruhr-uni-bochum.de (localhost [127.0.0.1]) by out3.mail.ruhr-uni-bochum.de (Postfix mo-ext) with ESMTP id 4M8JhJ0tQVz8SCy for ; Fri, 19 Aug 2022 13:00:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ruhr-uni-bochum.de; s=mail-2017; t=1660906848; bh=dNj1koO+HXcVxxYsHDD+FXJ6LubIlgbw6sYFOG861OU=; h=Date:From:To:Subject:In-Reply-To:References:From; b=Y6KDFXW0mSsisPbvkSfBU6/Qlsjh+sPoH/ADBS3+DWqLsirGEDyMyF/xjfPP4kaz7 rfg8tOHK54MLgrA18V7cmAWNbx69/OjPbiGpyFK8h+hNZDOh5sKc3ASSHMnOzj86yr Oom6AAdPm/eRgo28NNoc46xIYpeohFZIWFyLN1m0= Original-Received: from out3.mail.ruhr-uni-bochum.de (localhost [127.0.0.1]) by mx3.mail.ruhr-uni-bochum.de (Postfix idis) with ESMTP id 4M8JhJ062Pz8SFD for ; Fri, 19 Aug 2022 13:00:47 +0200 (CEST) X-Envelope-Sender: X-RUB-Notes: Internal origin=134.147.42.236 Original-Received: from mail2.mail.ruhr-uni-bochum.de (mail2.mail.ruhr-uni-bochum.de [134.147.42.236]) by out3.mail.ruhr-uni-bochum.de (Postfix mi-int) with ESMTP id 4M8JhH5fVNz8SDZ for ; Fri, 19 Aug 2022 13:00:47 +0200 (CEST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.104.1 at mx3.mail.ruhr-uni-bochum.de Original-Received: from [127.0.0.1] (dslb-002-206-238-112.002.206.pools.vodafone-ip.de [2.206.238.112]) by mail2.mail.ruhr-uni-bochum.de (Postfix) with ESMTPSA id 4M8JhH21QVzDgyl for ; Fri, 19 Aug 2022 13:00:47 +0200 (CEST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.104.2 at mail2.mail.ruhr-uni-bochum.de In-Reply-To: <828eadbc-c2bf-c4ab-0833-96c55011d36c@firemail.cc> Received-SPF: pass client-ip=134.147.53.155; envelope-from=daniel.meissner-i4k@ruhr-uni-bochum.de; helo=out3.mail.ruhr-uni-bochum.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18528 Archived-At: Hi, Am 17=2E August 2022 13:50:46 MESZ schrieb Gentoo Arch : > Hi, >=20 > I'd like to ask for your advice=2E >=20 > I'm trying to figure out how Guile webserver works to develop a simple B= BS=C2=A0 and I'm kinda stuck with POST request=2E >=20 > My Guile script generates a form on any path and the form sends to "/pos= t" path, where I can easily render content sent by the form=2E >=20 > (define (show-page request body) > =C2=A0 (if (equal? (get-path request) ; get-path is my other function to= retrieve the path > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 '("post")) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (values '((content-type =2E (text/plain))= ) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 body) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (respond ; literally a respond template f= rom webserver doc > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 `((h1 "Oops!") > =C2=A0=C2=A0 =C2=A0 (p (@ (id "test")) "The path: " ,(get-path request)) > =C2=A0=C2=A0 =C2=A0 (form (@ (method "POST") (action "/post")) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (label (@ (for "= test")) "Content: ") > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (input (@ (id "t= est") (type "text") (name "content"))) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (input (@ (type = "submit") (value "Submit")))))))) >=20 > But I would like to operate upon the content the form sends like web app= s usually do: insert it in the database or simply write to file=2E So my qu= estion is how I can proceed with something like that: >=20 > (define tf (open-file "test-file=2Etxt" "a")) >=20 > (define (show-page request body) > =C2=A0 (if (equal? (get-path request) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 '("post")) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((values '((content-type =2E (text/plain)= )) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 body) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (display body tf)); I'd like to wri= te/append body to the file, but it does nothing > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (respond > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 `((h1 "Oops!") > =C2=A0=C2=A0 =C2=A0 (p (@ (id "test")) "The path: " ,(get-path request)) > =C2=A0=C2=A0 =C2=A0 (form (@ (method "POST") (action "/post")) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (label (@ (for "= test")) "Content: ") > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (input (@ (id "t= est") (type "text") (name "content"))) > =C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (input (@ (type = "submit") (value "Submit")))))))) >=20 > If I remove (values), it does write to a file (with a complaint in webse= rver output), but I'd also like to add some kind of redirect from "/post" p= age after the script has written stuff to file and I can't use two function= s per response=2E >=20 > Could you please advise how I can achieve this functionality? I think you probably want to replace the true-branch of your `if' form wit= h (begin (display body tf) (values '((content-type =2E (text/plain)) body)) It is important that the handler returns two values, so the `values' form = must come last in the sequence=2E These two return values make up the respo= nse=2E Best Daniel