From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Gentoo Arch Newsgroups: gmane.lisp.guile.user Subject: Operate upon POST request with Guile webserver Date: Wed, 17 Aug 2022 14:50:46 +0300 Message-ID: <828eadbc-c2bf-c4ab-0833-96c55011d36c@firemail.cc> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5168"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Wed Aug 17 13:53:54 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 1oOHcQ-00019I-Ge for guile-user@m.gmane-mx.org; Wed, 17 Aug 2022 13:53:54 +0200 Original-Received: from localhost ([::1]:34632 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOHcP-00069Q-H6 for guile-user@m.gmane-mx.org; Wed, 17 Aug 2022 07:53:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOHZn-0005Di-7v for guile-user@gnu.org; Wed, 17 Aug 2022 07:51:17 -0400 Original-Received: from [37.120.193.124] (port=33122 helo=mail.cock.li) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOHZh-0002Fa-DA for guile-user@gnu.org; Wed, 17 Aug 2022 07:51:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=firemail.cc; s=mail; t=1660737047; bh=CZA6Tf9HyV6V1OAttL0hl3wiv9I4NcyR6jFy5wgh0hc=; h=Date:To:From:Subject:From; b=JQ3qKH5UM4fTz1RkYXaBayv3mPBuXpdMViwouRJA3nJoZhs6aWAfqioNqNz8cnzAU FuutR/tvgqYqu8GAl0G9Ht1krgp2jSAqcPfrgV6vVb4zb1q1TOrjvnWQTRCsr8FeO6 XhT+5n+yQv4lx9zcGxKJh33lobRgEyS2zVJoo6fpx/68O/n8VVYOD7zamMzrmFkTIw 9P7ViMb3Y2BXMzcwWHBBBHA10a0YTD6XcPz/aTJHp1qY9nXwFX50AqFwqRz2i0j66w vFE3j6RDKIW0CrK+NedhF8wI+M87p78ozK+7aNfcnQi6RNeeC1PmgHkm43tDsAI/kG W7YZEsqzgfm6A== Content-Language: en-US X-Host-Lookup-Failed: Reverse DNS lookup failed for 37.120.193.124 (failed) Received-SPF: pass client-ip=37.120.193.124; envelope-from=gentoocore@firemail.cc; helo=mail.cock.li X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, HTML_MESSAGE=0.001, RDNS_NONE=0.793, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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:18522 Archived-At: Hi, I'd like to ask for your advice. I'm trying to figure out how Guile webserver works to develop a simple BBS  and I'm kinda stuck with POST request. My Guile script generates a form on any path and the form sends to "/post" path, where I can easily render content sent by the form. (define (show-page request body)   (if (equal? (get-path request) ; get-path is my other function to retrieve the path               '("post"))       (values '((content-type . (text/plain)))                body)       (respond ; literally a respond template from webserver doc        `((h1 "Oops!")      (p (@ (id "test")) "The path: " ,(get-path request))      (form (@ (method "POST") (action "/post"))            (label (@ (for "test")) "Content: ")            (input (@ (id "test") (type "text") (name "content")))            (input (@ (type "submit") (value "Submit")))))))) But I would like to operate upon the content the form sends like web apps usually do: insert it in the database or simply write to file. So my question is how I can proceed with something like that: (define tf (open-file "test-file.txt" "a")) (define (show-page request body)   (if (equal? (get-path request)               '("post"))       ((values '((content-type . (text/plain)))               body)        (display body tf)); I'd like to write/append body to the file, but it does nothing       (respond        `((h1 "Oops!")      (p (@ (id "test")) "The path: " ,(get-path request))      (form (@ (method "POST") (action "/post"))            (label (@ (for "test")) "Content: ")            (input (@ (id "test") (type "text") (name "content")))            (input (@ (type "submit") (value "Submit")))))))) If I remove (values), it does write to a file (with a complaint in webserver output), but I'd also like to add some kind of redirect from "/post" page after the script has written stuff to file and I can't use two functions per response. Could you please advise how I can achieve this functionality?