* extract headers from response record
@ 2023-08-09 14:18 Mortimer Cladwell
2023-08-09 22:23 ` wolf
2023-08-09 22:34 ` wolf
0 siblings, 2 replies; 5+ messages in thread
From: Mortimer Cladwell @ 2023-08-09 14:18 UTC (permalink / raw)
To: guile-user
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?
Thanks
Mortimer
^ permalink raw reply [flat|nested] 5+ messages in thread
* re: extract headers from response record
@ 2023-08-09 18:56 Mortimer Cladwell
0 siblings, 0 replies; 5+ messages in thread
From: Mortimer Cladwell @ 2023-08-09 18:56 UTC (permalink / raw)
To: guile-user
a couple more:
(pretty-print (record? a)) ==> #t
(pretty-print (record-predicate a)) ==> not-a-record-type #<<response>
version: (1 . 1) code: 204 reason-phrase: "ok" headers: ((date . #<date
nanosecond: 0 second: 43 minute: 52 hour: 18 day: 9 month: 8 year: 2023
zone-offset: 0>) (connection close) (server . "urbit/vere-2.11")
(set-cookie . "urbauth-~zod=0vao7n2.lcut2.mu17h.9dgil.2o48i; Path=/;
Max-Age=604800")) port: #<closed: file 7efddcb854d0>>
(pretty-print (record-constructor a)) ==> ice-9/boot-9.scm:963:4: In
procedure record-type-constructor:
not-a-record-type #<<response> version: (1 . 1) code: 204 reason-phrase:
"ok" headers: ((date . #<date nanosecond: 0 second: 30 minute: 53 hour: 18
day: 9 month: 8 year: 2023 zone-offset: 0>) (connection close) (server .
"urbit/vere-2.11") (set-cookie .
"urbauth-~zod=0v5.efbvj.h7hi9.8df2a.rh33o.4pv5f; Path=/; Max-Age=604800"))
port: #<closed: file 7f2d0b2b9930>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: extract headers from response record
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
2023-08-09 22:34 ` wolf
1 sibling, 1 reply; 5+ messages in thread
From: wolf @ 2023-08-09 22:23 UTC (permalink / raw)
To: Mortimer Cladwell; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 2588 bytes --]
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.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: extract headers from response record
2023-08-09 14:18 extract headers from response record Mortimer Cladwell
2023-08-09 22:23 ` wolf
@ 2023-08-09 22:34 ` wolf
1 sibling, 0 replies; 5+ messages in thread
From: wolf @ 2023-08-09 22:34 UTC (permalink / raw)
To: Mortimer Cladwell; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 3365 bytes --]
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'?
I apologize for my previous message, apparently my reading comprehension is
really low at this time of day. Anyway, to actually answer the question:
response-headers is the procedure you are looking for. You are already using
it, and it works for me (without the receive, so maybe consider dropping it
since it is not necessary):
((accept-ranges bytes)
(cache-control (max-age . 604800))
(content-type text/html (charset . "UTF-8"))
(date .
#<date nanosecond: 0 second: 32 minute: 30 hour: 22 day: 9 month: 8 year: 2023 zone-offset: 0>)
(etag "3147526947" . #t)
(expires
.
#<date nanosecond: 0 second: 32 minute: 30 hour: 22 day: 16 month: 8 year: 2023 zone-offset: 0>)
(last-modified
.
#<date nanosecond: 0 second: 26 minute: 18 hour: 7 day: 17 month: 10 year: 2019 zone-offset: 0>)
(server . "EOS (vny/044F)")
(content-length . 1256)
(connection close))
Expression evaluated was:
(use-modules (ice-9 pretty-print)
(ice-9 receive)
(web client)
(web response))
(define (urbit-http-connect)
(let* ((uri "http://example.org")
(data (string-append "password=" "lidlut-tabwed-pillex-ridrup"))
(response (http-request uri #:method 'POST #:body data)))
(pretty-print (response-headers response))))
(urbit-http-connect)
> How do I determine the record type?
> Thanks
> Mortimer
W.
--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: extract headers from response record
2023-08-09 22:23 ` wolf
@ 2023-08-10 10:11 ` Mortimer Cladwell
0 siblings, 0 replies; 5+ messages in thread
From: Mortimer Cladwell @ 2023-08-10 10:11 UTC (permalink / raw)
To: Mortimer Cladwell, guile-user
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.
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-08-10 10:11 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2023-08-09 22:34 ` wolf
-- strict thread matches above, loose matches on Subject: below --
2023-08-09 18:56 Mortimer Cladwell
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).