web: Add 2.0.5 workaround for responses without content-length.

* guix/web.scm (read-response-body*)[when-guile<=2.0.5]: Support
  responses without content-length.
  Reported by Andreas Enge <andreas@enge.fr>.
This commit is contained in:
Ludovic Courtès 2013-04-27 23:00:21 +02:00
parent c4ca12c15b
commit 61ef22f432

View file

@ -121,12 +121,15 @@ (define bad-response
#:keep-alive? #t))) #:keep-alive? #t)))
(get-bytevector-all chunk-port)) (get-bytevector-all chunk-port))
(let ((nbytes (response-content-length r))) (let ((nbytes (response-content-length r)))
(and nbytes ;; Backport of Guile commit 84dfde82ae8f6ec247c1c147c1e2ae50b207bad9
;; ("fix response-body-port for responses without content-length").
(if nbytes
(let ((bv (get-bytevector-n (response-port r) nbytes))) (let ((bv (get-bytevector-n (response-port r) nbytes)))
(if (= (bytevector-length bv) nbytes) (if (= (bytevector-length bv) nbytes)
bv bv
(bad-response "EOF while reading response body: ~a bytes of ~a" (bad-response "EOF while reading response body: ~a bytes of ~a"
(bytevector-length bv) nbytes))))))) (bytevector-length bv) nbytes)))
(get-bytevector-all (response-port r))))))
;; Install this patch only on Guile 2.0.5. ;; Install this patch only on Guile 2.0.5.
(when (version>? "2.0.6" (version)) (when (version>? "2.0.6" (version))