download: Follow HTTP redirections.
* guix/build/download.scm (http-fetch): Follow the redirection when CODE is 302.
This commit is contained in:
		
							parent
							
								
									87f5d36630
								
							
						
					
					
						commit
						270246defe
					
				
					 1 changed files with 16 additions and 8 deletions
				
			
		| 
						 | 
					@ -101,14 +101,22 @@ which is not available during bootstrap."
 | 
				
			||||||
                 (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
 | 
				
			||||||
 | 
					      ((200)                                      ; OK
 | 
				
			||||||
       (begin
 | 
					       (begin
 | 
				
			||||||
         (call-with-output-file file
 | 
					         (call-with-output-file file
 | 
				
			||||||
           (lambda (p)
 | 
					           (lambda (p)
 | 
				
			||||||
             (put-bytevector p bv)))
 | 
					             (put-bytevector p bv)))
 | 
				
			||||||
          file)
 | 
					         file))
 | 
				
			||||||
 | 
					      ((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)
 | 
					       (error "download failed" (uri->string uri)
 | 
				
			||||||
               code (response-reason-phrase resp)))))
 | 
					              code (response-reason-phrase resp))))))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
(define-syntax-rule (false-if-exception* body ...)
 | 
					(define-syntax-rule (false-if-exception* body ...)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Reference in a new issue