From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mortimer Cladwell Newsgroups: gmane.lisp.guile.user Subject: Re: extract headers from response record Date: Thu, 10 Aug 2023 06:11:55 -0400 Message-ID: References: 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="14195"; mail-complaints-to="usenet@ciao.gmane.io" To: Mortimer Cladwell , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Aug 10 12:12:45 2023 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 1qU2er-0003W3-O6 for guile-user@m.gmane-mx.org; Thu, 10 Aug 2023 12:12:45 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qU2eJ-00036q-AE; Thu, 10 Aug 2023 06:12:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qU2eI-00036h-6G for guile-user@gnu.org; Thu, 10 Aug 2023 06:12:10 -0400 Original-Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qU2eG-0002P7-En for guile-user@gnu.org; Thu, 10 Aug 2023 06:12:09 -0400 Original-Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-26b0b92e190so300336a91.1 for ; Thu, 10 Aug 2023 03:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691662327; x=1692267127; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=IRtP8ZL39HtFn1njJd0FDMKUAfr5zwdBkApVkgFSRPQ=; b=Nd+AKfUMA4F53Q7CA3YtILFXqTrGvE0eBfRZMX1zLZA9tuHa03APGCUo62fZ9TM8/8 2BH4cEpKnfr9ohJJwtxEJFf+Cvz5mzQEo6Jnr1TWKkU28B1gUebbLLS//xR1UiaqsnwI RwFoCSrZmJmihPtOO5nYAjBfrV7NfGbyE0usU9EMdXqDAca2IKWA7X79CmHCLlKxHcWn EYG7/SWczCsAMfhbz+bcTYVT+hEYrdOYium8XS95GxMF+yAZo9WymYn5fYZO2E/sXXaJ XFSnEJ5cHgbBYH5sKS9Vf7kcki2oQPiZ9fClbM8OeKiOB3/tA3lka2jSQDX9VECP5fiP 5BCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691662327; x=1692267127; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IRtP8ZL39HtFn1njJd0FDMKUAfr5zwdBkApVkgFSRPQ=; b=Ln+9O6xAx4oFf6xisgtweof23O8B/ZjOCI5n473sbKWJItXhCW9cDIrb3zgfhUGgeU sp+ltAxG9iaHKb+TzziHJLtljBOZ4p5GnykbXOLmvQiLHU68UK/4/qbHm0q42NvSOeEm MstitA2LL1Plt42vC3wOqzh1ET3U7qWI9oiVGqEy98DT+G5o1zHjR18B7+2Begj3B1eg SMMMcygrvD5kisItIv8B/snAY6cRXyEUP0geoaYgk3eQ51FqexV4SxQXxSq4x/QbgR7R gXG3/GKEAtNXi+J5cgEACTJBXw9zB4TqTAmi+dAHusN/mgSobo5n53eEmgz1lFKHRd2h MH7w== X-Gm-Message-State: AOJu0YxXi/TnAI3LG2J4IfjaUBZuw7mcrNG4OQ0X7jaefxCTDji6CROB vhbnDOtRGgO5AcGqEGo0TYBwJRWRanKUw4vJyw8= X-Google-Smtp-Source: AGHT+IE5ys4WI2zDAjmpSLmn5pxh5ve1FROz8izROE6+FQj0c6hXhBFr8xdL4BRNMJsnm4IOhdG6IvZHVm/xMeZPu0w= X-Received: by 2002:a17:90a:1590:b0:262:c41e:1fcb with SMTP id m16-20020a17090a159000b00262c41e1fcbmr2105618pja.14.1691662326897; Thu, 10 Aug 2023 03:12:06 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=mbcladwell@gmail.com; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:19141 Archived-At: Thanks Wolf. My mistake was defining a response record earlier in the script which I did not show. Once removed everything works as expected. BTW works with or without receive because body is empty (#f). Thanks again Mortimer On Wed, Aug 9, 2023 at 6:23=E2=80=AFPM wolf wrote: > On 2023-08-09 10:18:05 -0400, Mortimer Cladwell wrote: > > Hi, > > I am running a local fake Urbit zod on port 8080. I want to submit an > > http-request and obtain an urbauth id cookie. I run the following metho= d: > > > > (use-modules (web client)(web response) (srfi srfi-9)(oop goops) (ice-9 > > receive) (ice-9 pretty-print)) > > > > (define (urbit-http-connect) > > (let* ((uri "http://localhost:8080/~/login") > > (data (string-append "password=3D" "lidlut-tabwed-pillex-ridru= p")) > > (a (receive (response body) > > (http-request uri #:method 'POST #:body data) > > response))) > > (pretty-print a))) > > > > =3D=3D> #< version: (1 . 1) code: 204 reason-phrase: "ok" hea= ders: > > ((date . # month: > > 8 year: 2023 zone-offset: 0>) (connection close) (server . > > "urbit/vere-2.11") (set-cookie . > > "urbauth-~zod=3D0v7.126dd.8rbvk.lga05.jvieb.287to; Path=3D/; > Max-Age=3D604800")) > > port: #> > > > > Below I substitute (pretty-print a) with various commands and show the > > response: > > > > (pretty-print (class-of a)) =3D=3D> #< <> 7f721fc4c28= 0> > > (pretty-print (record? a)) =3D=3D> #t > > (pretty-print (response? a)) =3D=3D> #f > > > > (pretty-print (response-headers a)) =3D=3D> In procedure response-head= ers: > > Wrong type argument: #< version: (1 . 1) code: 204 > reason-phrase: > > "ok" headers: ((date . # > day: 9 month: 8 year: 2023 zone-offset: 0>) (connection close) (server = . > > "urbit/vere-2.11") (set-cookie . > > "urbauth-~zod=3D0v5.9pm4c.pa0qd.00hao.vsq1p.h37hh; Path=3D/; > Max-Age=3D604800")) > > port: #> > > > > So I have a record that looks like a record but isn't. How d= o > I > > extract the headers from this 'response'? > > How do I determine the record type? > > You are using the (receive) in a wrong way I believe. The value you name= d > body > holds the, well, body, but you are just throwing it away. Try something > like > this, it will print both the response and the body: > > (use-modules (ice-9 receive) > (web client)) > > (define (urbit-http-connect) > (let* ((uri "http://example.org") > (data (string-append "password=3D" "lidlut-tabwed-pillex-ridrup"= ))) > (receive (response body) > (http-request uri #:method 'POST #:body data) > (format #t "~s~%~s~%" response body)))) > > (urbit-http-connect) > > > Thanks > > Mortimer > > W. > > -- > There are only two hard things in Computer Science: > cache invalidation, naming things and off-by-one errors. >