From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sunjoong Lee Newsgroups: gmane.lisp.guile.user Subject: Re: read-response-body of (web response) depends on Content-Length but ... Date: Fri, 27 Apr 2012 19:00:11 +0900 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e6daa637ca7a1f04bea62c86 X-Trace: dough.gmane.org 1335520847 8999 80.91.229.3 (27 Apr 2012 10:00:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 27 Apr 2012 10:00:47 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Apr 27 12:00:47 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 1SNhyo-0002ah-Uo for guile-user@m.gmane.org; Fri, 27 Apr 2012 12:00:47 +0200 Original-Received: from localhost ([::1]:43804 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNhyo-0003ma-DL for guile-user@m.gmane.org; Fri, 27 Apr 2012 06:00:46 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNhyi-0003mH-La for guile-user@gnu.org; Fri, 27 Apr 2012 06:00:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNhyd-0006ZW-L4 for guile-user@gnu.org; Fri, 27 Apr 2012 06:00:40 -0400 Original-Received: from mail-wg0-f49.google.com ([74.125.82.49]:42174) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNhyd-0006ZB-8J for guile-user@gnu.org; Fri, 27 Apr 2012 06:00:35 -0400 Original-Received: by wgbds1 with SMTP id ds1so372365wgb.30 for ; Fri, 27 Apr 2012 03:00:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=nHScNrg9WwQcuxmuoI3L/AnDUh63yoahk2UAbSomk88=; b=BMz4EOMj59pdRU/vQX+a4NFxsxcxQ8gG7EYXoWg9CcrYQhMS7DvXUYbIs0VqkxL+3X xBjYaWdAWFC/Xb2jZJtEaTFAZ3mocPgcwb7g5wldsX44eFvtCc8UYpUmrlp2eawZhqmM /RXs4l97gzqX+Vu8h7tihDI0cOjr4NaLzYtk4KHT6VYPHaZ/cnl8TUeWLV+PB9uVEnlQ nW1mKW/7/ktEET+PWn9JQoVb+jbLHOEVlalf5rWJEgNjDwRkfw3QrnnNhHx02KEU4Wvn YnOMeYq4L0FhiBfBODtoP8urCdsfofmZm3KQHgpsCrSKV689RMzKvhw4sjiRd19JdTy5 Vpvg== Original-Received: by 10.216.142.226 with SMTP id i76mr5429899wej.28.1335520832157; Fri, 27 Apr 2012 03:00:32 -0700 (PDT) Original-Received: by 10.223.93.206 with HTTP; Fri, 27 Apr 2012 03:00:11 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.49 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:9404 Archived-At: --0016e6daa637ca7a1f04bea62c86 Content-Type: text/plain; charset=UTF-8 Below is a urgent patch of response.scm: --- /usr/share/guile/2.0/web/response.scm 2012-04-22 04:36:06.753878689 +0900 +++ response.scm 2012-04-27 18:49:16.499881816 +0900 @@ -217,13 +217,16 @@ (define (read-response-body r) "Reads the response body from @var{r}, as a bytevector. Returns @code{#f} if there was no response body." + (let ((te (response-transfer-encoding r))) + (if (and te (eq? 'chunked (car (car te)))) + (get-bytevector-all (response-port r)) (let ((nbytes (response-content-length r))) (and nbytes (let ((bv (get-bytevector-n (response-port r) nbytes))) (if (= (bytevector-length bv) nbytes) bv (bad-response "EOF while reading response body: ~a bytes of ~a" - (bytevector-length bv) nbytes)))))) + (bytevector-length bv) nbytes)))))))) (define (write-response-body r bv) "Write @var{body}, a bytevector, to the port corresponding to the HTTP @@ -269,6 +272,7 @@ (define-response-accessor content-type #f) (define-response-accessor expires #f) (define-response-accessor last-modified #f) +(define-response-accessor transfer-encoding '()) ;; Response headers ;; Above patch is just a patch. 2012/4/27 Sunjoong Lee > I googled and found http://tools.ietf.org/html/rfc2616 . > > In a section of "4.4 Message Length": > 2.If a Transfer-Encoding header field (section 14.41) is present and > has any value other than "identity", then the transfer-length is > defined by use of the "chunked" transfer-coding (section 3.6), > unless the message is terminated by closing the connection. > 3.If a Content-Length header field (section 14.13) is present, its > decimal value in OCTETs represents both the entity-length and the > transfer-length. The Content-Length header field MUST NOT be sent > if these two lengths are different (i.e., if a Transfer-Encoding > header field is present). If a message is received with both a > Transfer-Encoding header field and a Content-Length header field, > the latter MUST be ignored. > --0016e6daa637ca7a1f04bea62c86 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Below is a urgent patch of=C2=A0response.scm:

--- /usr/share/guile/2.0/web/response.scm 2012-04-22 04:36:06.75387= 8689 +0900
+++ response.scm 2012-04-27 18:49:16.499881816 +0900
<= div class=3D"gmail_extra">@@ -217,13 +217,16 @@
=C2=A0(define (read-response-body r)
=C2=A0 =C2=A0"Reads the response body from = @var{r}, as a bytevector. =C2=A0Returns
=C2= =A0@code{#f} if there was no response body."
+ =C2=A0(let ((te (response-transfer-encoding r)))
+ =C2=A0 =C2=A0(if (and te (eq? 'chunked (ca= r (car te))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0= (get-bytevector-all (response-port r))
=C2= =A0 =C2=A0(let ((nbytes (response-content-length r)))
=C2=A0 =C2=A0 =C2=A0(and nbytes
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (let ((bv (get-bytevect= or-n (response-port r) nbytes)))
=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (if (=3D (bytevector-length bv) nbytes)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 bv
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 (bad-response "EOF while reading response bod= y: ~a bytes of ~a"
- =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0(bytevector-length bv) nbytes))))))
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(bytevector-length bv) = nbytes))))))))
=C2=A0
=C2=A0(define (write-response-body r bv)
=C2=A0 =C2=A0"Write @var{body}, a bytevector, to the port correspondin= g to the HTTP
@@ -269,6 +272,7 @@
=C2=A0(define-response-accessor content-type #f)
=C2=A0(define-response-accessor expires #f)
=C2=A0(define-response-accessor last-modified #f)
+(define-response-accessor transfer-encoding = 9;())
=C2=A0
=C2=A0;; Response headers
=C2=A0;;
<= div>
Above patch is just a patch.

2012/4/27 Sunjoong Lee <sunjoong@gmail.com>
I googled and found=C2=A0http://tools.ietf.org/html/rfc261= 6 .

In a section of "4.4 Message Length":
=C2=A0 2.If a Transfe= r-Encoding header field (section 14.41) is present and
=C2=A0 =C2=A0 =C2=A0has any value other than "identity&quo= t;, then the transfer-length is
=C2=A0 =C2=A0 =C2=A0defined by use of the "= chunked" transfer-coding (section 3.6),
=C2=A0 =C2=A0 =C2=A0unless the message is terminated by closing the conne= ction.
=C2=A0 3.If a Content-Length header field (secti= on 14.13) is present, its
=C2=A0 =C2=A0 =C2= =A0decimal value in OCTETs represents both the entity-length and the
<= div class=3D"gmail_extra"> =C2=A0 =C2=A0 =C2=A0transfer-length. The Content-Length header field MUST N= OT be sent
=C2=A0 =C2=A0 =C2=A0if these two= lengths are different (i.e., if a Transfer-Encoding
=C2=A0 =C2=A0 =C2=A0header field is present). If a message is rec= eived with both a
=C2=A0 =C2=A0 =C2=A0Transfer-Encoding header fie= ld and a Content-Length header field,
=C2= =A0 =C2=A0 =C2=A0the latter MUST be ignored.
= --0016e6daa637ca7a1f04bea62c86--