Index: http-client.scm
===================================================================
--- http-client.scm	(revision 359)
+++ http-client.scm	(working copy)
@@ -163,7 +163,7 @@
                    (fprintf o "Content-Length: ~A\r\n\r\n" (string-length b))
                    (display b o) )
                  (display "Content-Length: 0\r\n\r\n" o) )
-             (let ([header (read-line i)])
+             (let ([header (read-line i (http:read-line-limit))])
                (let ([a (http:read-request-attributes i)])
                  (cond ((and in out))
                        ((is-keep-alive? header a)
@@ -178,12 +178,27 @@
                       (else (signal exn))))))))))
 
 (define (read-body a i)
-  (read-string
-   (cond ((alist-ref "content-length" a string=?)
-          => string->number)
-         (else
-          #f))
-   i))
+  (cond ((string-ci=? (alist-ref "transfer-encoding" a string=? "") "chunked")
+         (let ([limit (http:read-line-limit)])
+           (let loop ([body ""])
+             (let* ([size-line (read-line i limit)]
+                    [size (string->number size-line 16)])
+               (cond ((not (fixnum? size))
+                      (error "http" "read-body" "failed to parse chunk size."))
+                     ((> size 0)
+                      (let ([b (read-string size i)])
+                        (read-line i limit) ; to drop CRLF
+                        (loop (string-append body b))))
+                     (else
+                      (http:read-request-attributes i) ; to drop footer+CRLF
+                      body))))))
+        (else
+         (read-string
+          (cond ((alist-ref "content-length" a string=?)
+                 => string->number)
+                (else
+                 #f))
+          i))))
 
 (define (http:GET req)
   (let-values ([(header a i o) (http:send-request req)])
