From e722af7522bd4e7625b876f6c7a3525e89d96e7c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Fri, 9 Nov 2012 00:19:20 +0100
Subject: [PATCH] http: Check the HTTP response code, and bail if not 200.

* guix/build/http.scm (http-fetch): Check RESP's code; error out when
  it's not 200.
---
 guix/build/http.scm | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/guix/build/http.scm b/guix/build/http.scm
index a3f9f9a870a..a0fc4528442 100644
--- a/guix/build/http.scm
+++ b/guix/build/http.scm
@@ -17,8 +17,9 @@
 ;;; along with Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (guix build http)
-  #:use-module (web client)
   #:use-module (web uri)
+  #:use-module (web client)
+  #:use-module (web response)
   #:use-module (rnrs io ports)
   #:use-module (srfi srfi-11)
   #:export (http-fetch))
@@ -83,8 +84,14 @@ (define (http-fetch url file)
                 ((connection)
                  (open-connection-for-uri uri))
                 ((resp bv)
-                 (http-get uri #:port connection #:decode-body? #f)))
-    (call-with-output-file file
-      (lambda (p)
-        (put-bytevector p bv))))
-  file)
+                 (http-get uri #:port connection #:decode-body? #f))
+                ((code)
+                 (response-code resp)))
+    (if (= 200 code)
+        (begin
+          (call-with-output-file file
+            (lambda (p)
+              (put-bytevector p bv)))
+          file)
+        (error "download failed" url
+               code (response-reason-phrase resp)))))
-- 
GitLab