From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.user Subject: Re: Using guile's web client Date: Thu, 15 Mar 2012 09:43:17 +0800 Message-ID: References: <20120315000554.6e1918df@laptop.homenet> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec51dd8134f3f6b04bb3e37e5 X-Trace: dough.gmane.org 1331775812 2783 80.91.229.3 (15 Mar 2012 01:43:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 15 Mar 2012 01:43:32 +0000 (UTC) Cc: Guile User To: Chris Vine Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Mar 15 02:43:31 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S7ziz-0004n1-2H for guile-user@m.gmane.org; Thu, 15 Mar 2012 02:43:29 +0100 Original-Received: from localhost ([::1]:42641 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7ziy-0001BB-6o for guile-user@m.gmane.org; Wed, 14 Mar 2012 21:43:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33915) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7zis-0001AD-QE for guile-user@gnu.org; Wed, 14 Mar 2012 21:43:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S7zip-0004Vn-Ro for guile-user@gnu.org; Wed, 14 Mar 2012 21:43:22 -0400 Original-Received: from mail-vx0-f169.google.com ([209.85.220.169]:46669) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S7zip-0004Ve-Js for guile-user@gnu.org; Wed, 14 Mar 2012 21:43:19 -0400 Original-Received: by vcbfk14 with SMTP id fk14so3281312vcb.0 for ; Wed, 14 Mar 2012 18:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=TN1lAV74cXh67sVF4vcIsdp9HM9krWY2uZIzThhdsmE=; b=ekgy8XMGPiEYKD4EXup6CjkTpQlsdH1ualFMeIa7t26t2A8ZwmgSiYkeBu5R22S8Fr VpHh8bUuYE8HJTwpXtC+8NIpIHhODIquoG6Ln1V9NeEIRqIHVVMDLZ9tBOuB6PLs+K4s x1ksqeV8QAhnT2b5DzucTuMTLa53lk0IYy13jQaWswB02LqLWrviKDqi3wE25fzfbv8q Pk9l5MlXq7Y6c7HvbC5eXO6ZXSQyGp9I/A8E5ujW+W7iLLaV3wzt1WX8k2t1LQWURUm7 b7QlLeyWSLPmqyGMiFaDaVhqzZHTJjN7dBozBHM6t7fjxIHkK7NPgbcubUUmwmQLrVma vPyQ== Original-Received: by 10.52.174.162 with SMTP id bt2mr3633370vdc.56.1331775797149; Wed, 14 Mar 2012 18:43:17 -0700 (PDT) Original-Received: by 10.52.88.231 with HTTP; Wed, 14 Mar 2012 18:43:17 -0700 (PDT) In-Reply-To: <20120315000554.6e1918df@laptop.homenet> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.169 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9342 Archived-At: --bcaec51dd8134f3f6b04bb3e37e5 Content-Type: text/plain; charset=UTF-8 I'm afraid it's a real bug. read-response-body didn't check before it call bytevector-length. But actually, all the data has already been read. When it encounters , it should return the body immediately. The bug is, it checks bytevector-length first which cause (bytevector-length ). I didn't realize this bug before, because I read the body by block which always constrains the bytevector length within the range of content-length. But I'm not going to send a patch for this bug. Because I've sent another patch to rewrite the whole read-response-body which get rid of this bug already. And it will return the received body data when any error or break happens. The old one didn't do this job. Here is the thread: http://lists.gnu.org/archive/html/guile-devel/2012-03/msg00116.html What do you think? Regard. On Thu, Mar 15, 2012 at 8:05 AM, Chris Vine wrote: > Hi, > > I have been playing around with guile-2.0.5's high-level web modules. > In order to see if I understood them, I tried about the simplest thing > I could think of: a GET request to checkip.dyndns.com to obtain my IP > address. > > The following code works correctly provided I leave the commented out > code commented out: > > (use-modules > (web uri) > (web response) > (rnrs bytevectors) > (web client)) > > ((lambda() > (let ((uri (build-uri 'http > #:host "checkip.dyndns.com" > #:port 80 > #:path "/"))) > (display uri) > (newline) > (let ((r (http-get uri #:keep-alive? #t))) > (if r > (begin > (display r)(newline) > ;; (display (read-response-body r))(newline) > ) > (begin > (display "Can't obtain response body") > (newline))))))) > > It outputs: > > #< scheme: http userinfo: #f host: "checkip.dyndns.com" port: 80 > path: "/" query: #f fragment: #f> > #< version: (1 . 1) code: 200 reason-phrase: "OK" headers: > ((content-type text/html) (server . "DynDNS-CheckIP/1.0") (connection > close) (cache-control no-cache) (pragma no-cache) (content-length . 105)) > port: #> > > The contents of the response object mirrors the response obtained by > node.js with the equivalent code written in javascript, including the > content length, so the response object appears to be correct. However, > if I try to obtain the response body by uncommenting the call to > read-response-body, I get an error: > > Backtrace: > In ice-9/boot-9.scm: > 149: 10 [catch #t # ...] > 157: 9 [#] > In unknown file: > ?: 8 [catch-closure] > In ice-9/boot-9.scm: > 63: 7 [call-with-prompt prompt0 ...] > In ice-9/eval.scm: > 407: 6 [eval # #] > In ice-9/boot-9.scm: > 2111: 5 [save-module-excursion # ice-9/boot-9.scm:3646:3 ()>] > 3653: 4 [#] > In unknown file: > ?: 3 [load-compiled/vm > "/home/chris/.cache/guile/ccache/2.0-LE-4-2.0/home/chris/src/scheme/my-ip-test.scm.go"] > In /home/chris/src/scheme/my-ip-test.scm: > 18: 2 [#] > In web/response.scm: > 223: 1 [read-response-body #] > In unknown file: > ?: 0 [bytevector-length #] > > ERROR: In procedure bytevector-length: > ERROR: In procedure scm_c_bytevector_length: Wrong type argument in > position 1 (expecting bytevector): # > > The error is in the procedure call to read-response-body. Is this a > bug in guile-2, or am I doing something wrong? > > Chris > > --bcaec51dd8134f3f6b04bb3e37e5 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I'm afraid it's a real bug.
read-response-body didn&= #39;t check <eof> before it call bytevector-length.=C2=A0
B= ut actually, all the data has already been read. When it encounters <eof= >, it should return the body=C2=A0immediately. The bug is, it checks byt= evector-length first which cause (bytevector-length <eof>).
I didn't realize this bug before, because I read the body by block= which always constrains the bytevector length within the range of content-= length.=C2=A0

But I'm not going to send a patch for this bug. Be= cause I've sent another patch to rewrite the whole read-response-body w= hich get rid of this bug already. And it will return the received body data= when any error or break happens. The old one didn't do this job.
Here is the thread:

Regard.

On Thu, Mar 15,= 2012 at 8:05 AM, Chris Vine <chris@cvine.freeserve.co.uk> wrote:
Hi,

I have been playing around with guile-2.0.5's high-level web modules. In order to see if I understood them, I tried about the simplest thing
I could think of: a GET request to checkip.dyndns.com to obtain my IP
address.

The following code works correctly provided I leave the commented out
code commented out:

(use-modules
=C2=A0(web uri)
=C2=A0(web response)
=C2=A0(rnrs bytevectors)
=C2=A0(web client))

((lambda()
=C2=A0 (let ((uri (build-uri 'http
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 #:host "checkip.dyndns.com"
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 #:port 80
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 #:path "/")))
=C2=A0 =C2=A0 (display uri)
=C2=A0 =C2=A0 (newline)
=C2=A0 =C2=A0 (let ((r (http-get uri #:keep-alive? #t)))
=C2=A0 =C2=A0 =C2=A0 (if r
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (begin
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (display r)(newline)
;; =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (display (read-response-body r))(newl= ine)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 )
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (begin
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (display "Can't obtain = response body")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (newline)))))))

It outputs:

#<<uri> scheme: http userinfo: #f host: "checkip.dyndns.com" port: 80 p= ath: "/" query: #f fragment: #f>
#<<response> version: (1 . 1) code: 200 reason-phrase: "OK&qu= ot; headers: ((content-type text/html) (server . "DynDNS-CheckIP/1.0&q= uot;) (connection close) (cache-control no-cache) (pragma no-cache) (conten= t-length . 105)) port: #<input-output: socket 6>>

The contents of the response object mirrors the response obtained by
node.js with the equivalent code written in javascript, including the
content length, so the response object appears to be correct. =C2=A0However= ,
if I try to obtain the response body by uncommenting the call to
read-response-body, I get an error:

Backtrace:
In ice-9/boot-9.scm:
=C2=A0149: 10 [catch #t #<catch-closure 81e9280> ...]
=C2=A0157: 9 [#<procedure 81b38c0 ()>]
In unknown file:
=C2=A0 ?: 8 [catch-closure]
In ice-9/boot-9.scm:
=C2=A063: 7 [call-with-prompt prompt0 ...]
In ice-9/eval.scm:
=C2=A0407: 6 [eval # #]
In ice-9/boot-9.scm:
2111: 5 [save-module-excursion #<procedure 81a1060 at ice-9/boot-9.scm:3= 646:3 ()>]
3653: 4 [#<procedure 81a1060 at ice-9/boot-9.scm:3646:3 ()>]
In unknown file:
=C2=A0 ?: 3 [load-compiled/vm "/home/chris/.cache/guile/ccache/2.0-LE= -4-2.0/home/chris/src/scheme/my-ip-test.scm.go"]
In /home/chris/src/scheme/my-ip-test.scm:
=C2=A018: 2 [#<procedure 81ffd90 ()>]
In web/response.scm:
=C2=A0223: 1 [read-response-body #]
In unknown file:
=C2=A0 ?: 0 [bytevector-length #<eof>]

ERROR: In procedure bytevector-length:
ERROR: In procedure scm_c_bytevector_length: Wrong type argument in positio= n 1 (expecting bytevector): #<eof>

The error is in the procedure call to read-response-body. =C2=A0Is this a bug in guile-2, or am I doing something wrong?

Chris


--bcaec51dd8134f3f6b04bb3e37e5--