guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using guile's web client


From: Ian Price
Subject: Re: Using guile's web client
Date: Thu, 15 Mar 2012 01:14:31 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)

Chris Vine <address@hidden> writes:

> ((lambda()
>    (let ((uri (build-uri 'http
>                          #:host "checkip.dyndns.com"
>                          #:port 80
>                          #:path "/")))
>      (display uri)
>      (newline)
>      (let ((r (http-get uri #:keep-alive? #t)))
^^ there's your problem
>        (if r
>            (begin
>              (display r)(newline)
> ;;           (display (read-response-body r))(newline)
>              )
>            (begin
>              (display "Can't obtain response body")
>              (newline)))))))
snip.

>
> The error is in the procedure call to read-response-body.  Is this a
> bug in guile-2, or am I doing something wrong?
It's actually debatable whether or not this is your fault :). http-get
returns 2 values: the response and the body. When you call
read-response-body on the port, you are trying to read information that
has already been read, and so it is coming up with an (eof-object)
rather than the body. However, I notice that the manual doesn't actually
say that it returns two values, so that'll need to be fixed.

The correct way to write this code snippet is to use call-with-values
(or sugar such as receive or let-values), instead of let.

(let ((uri (build-uri 'http
                      #:host "checkip.dyndns.com"
                      #:port 80
                      #:path "/")))
  (call-with-values
      (lambda ()
        (http-get uri #:keep-alive? #t))
    (lambda (request body)
      ...)))

the request should (I think) always be a request object, so you don't
need to check it with if. Though, the body may be #f, so it's worth
checking that.


-- 
Ian Price

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]