Skip to content
Snippets Groups Projects
Commit 270246de authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

download: Follow HTTP redirections.

* guix/build/download.scm (http-fetch): Follow the redirection when CODE
  is 302.
parent 87f5d366
No related branches found
No related tags found
No related merge requests found
...@@ -101,14 +101,22 @@ (define (http-fetch uri file) ...@@ -101,14 +101,22 @@ (define (http-fetch uri file)
(http-get uri #:port connection #:decode-body? #f)) (http-get uri #:port connection #:decode-body? #f))
((code) ((code)
(response-code resp))) (response-code resp)))
(if (= 200 code) (case code
(begin ((200) ; OK
(call-with-output-file file (begin
(lambda (p) (call-with-output-file file
(put-bytevector p bv))) (lambda (p)
file) (put-bytevector p bv)))
(error "download failed" (uri->string uri) file))
code (response-reason-phrase resp))))) ((302) ; found (redirection)
(let ((uri (response-location resp)))
(format #t "following redirection to `~a'...~%"
(uri->string uri))
(close connection)
(http-fetch uri file)))
(else
(error "download failed" (uri->string uri)
code (response-reason-phrase resp))))))
(define-syntax-rule (false-if-exception* body ...) (define-syntax-rule (false-if-exception* body ...)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment