gnu-maintenance: Adjust `http-fetch' to the various Guile versions.
* guix/gnu-maintenance.scm (http-fetch): Try #:streaming? #t, or 'http-get*', or 'http-get' as a last resort. Check whether DATA is #f, a string, or an input port.
This commit is contained in:
parent
bdf06d8922
commit
5477e0342f
|
@ -66,12 +66,18 @@
|
||||||
(define (http-fetch uri)
|
(define (http-fetch uri)
|
||||||
"Return an input port containing the textual data at URI, a string."
|
"Return an input port containing the textual data at URI, a string."
|
||||||
(let*-values (((resp data)
|
(let*-values (((resp data)
|
||||||
(http-get (string->uri uri)))
|
(let ((uri (string->uri uri)))
|
||||||
|
;; Try hard to use the API du jour to get an input port.
|
||||||
|
(if (version>? "2.0.7" (version))
|
||||||
|
(if (defined? 'http-get*)
|
||||||
|
(http-get* uri)
|
||||||
|
(http-get uri)) ; old Guile, returns a string
|
||||||
|
(http-get uri #:streaming? #t)))) ; 2.0.8 or later
|
||||||
((code)
|
((code)
|
||||||
(response-code resp)))
|
(response-code resp)))
|
||||||
(case code
|
(case code
|
||||||
((200)
|
((200)
|
||||||
(cond ((string<=? (version) "2.0.5")
|
(cond ((not data)
|
||||||
(begin
|
(begin
|
||||||
;; XXX: Guile 2.0.5 and earlier did not support chunked transfer
|
;; XXX: Guile 2.0.5 and earlier did not support chunked transfer
|
||||||
;; encoding, which is required when fetching %PACKAGE-LIST-URL
|
;; encoding, which is required when fetching %PACKAGE-LIST-URL
|
||||||
|
@ -85,9 +91,10 @@
|
||||||
(response-transfer-encoding resp))
|
(response-transfer-encoding resp))
|
||||||
(error "download failed; use a newer Guile"
|
(error "download failed; use a newer Guile"
|
||||||
uri resp)))
|
uri resp)))
|
||||||
((string<=? (version) "2.0.7")
|
((string? data) ; old `http-get' returns a string
|
||||||
(open-input-string data))
|
(open-input-string data))
|
||||||
(else data)))
|
(else ; input port
|
||||||
|
data)))
|
||||||
(else
|
(else
|
||||||
(error "download failed" uri code
|
(error "download failed" uri code
|
||||||
(response-reason-phrase resp))))))
|
(response-reason-phrase resp))))))
|
||||||
|
|
Loading…
Reference in New Issue