unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Mortimer Cladwell <mbcladwell@gmail.com>
To: Mortimer Cladwell <mbcladwell@gmail.com>, guile-user@gnu.org
Subject: Re: extract headers from response record
Date: Thu, 10 Aug 2023 06:11:55 -0400	[thread overview]
Message-ID: <CAOcxjM7TmFv_V8QSz6BOTz_u2ZevJLMARsOGrafSfWoqtacbhQ@mail.gmail.com> (raw)
In-Reply-To: <ZNQR2RdKclhy25CY@ws>

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 PM wolf <wolf@wolfsden.cz> 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 method:
> >
> > (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=" "lidlut-tabwed-pillex-ridrup"))
> > (a (receive (response body)
> >   (http-request uri #:method 'POST #:body data)
> >      response)))
> >   (pretty-print a)))
> >
> > ==> #<<response> version: (1 . 1) code: 204 reason-phrase: "ok" headers:
> > ((date . #<date nanosecond: 0 second: 29 minute: 49 hour: 13 day: 9
> month:
> > 8 year: 2023 zone-offset: 0>) (connection close) (server .
> > "urbit/vere-2.11") (set-cookie .
> > "urbauth-~zod=0v7.126dd.8rbvk.lga05.jvieb.287to; Path=/;
> Max-Age=604800"))
> > port: #<closed: file 7fc2a569b3f0>>
> >
> > Below I substitute (pretty-print a) with various commands and show the
> > response:
> >
> > (pretty-print  (class-of a)) ==> #<<class> <<response>> 7f721fc4c280>
> > (pretty-print  (record? a)) ==> #t
> > (pretty-print  (response? a)) ==> #f
> >
> > (pretty-print  (response-headers a)) ==> In procedure response-headers:
> > Wrong type argument: #<<response> version: (1 . 1) code: 204
> reason-phrase:
> > "ok" headers: ((date . #<date nanosecond: 0 second: 34 minute: 0 hour: 14
> > day: 9 month: 8 year: 2023 zone-offset: 0>) (connection close) (server .
> > "urbit/vere-2.11") (set-cookie .
> > "urbauth-~zod=0v5.9pm4c.pa0qd.00hao.vsq1p.h37hh; Path=/;
> Max-Age=604800"))
> > port: #<closed: file 7fbaa95eb3f0>>
> >
> > So I have a record that looks like a <response> record but isn't. How do
> 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 named
> 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=" "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.
>


  reply	other threads:[~2023-08-10 10:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09 14:18 extract headers from response record Mortimer Cladwell
2023-08-09 22:23 ` wolf
2023-08-10 10:11   ` Mortimer Cladwell [this message]
2023-08-09 22:34 ` wolf
  -- strict thread matches above, loose matches on Subject: below --
2023-08-09 18:56 Mortimer Cladwell

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=CAOcxjM7TmFv_V8QSz6BOTz_u2ZevJLMARsOGrafSfWoqtacbhQ@mail.gmail.com \
    --to=mbcladwell@gmail.com \
    --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).