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

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.
parent 7bdd1f0e
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,9 @@ ...@@ -17,8 +17,9 @@
;;; along with Guix. If not, see <http://www.gnu.org/licenses/>. ;;; along with Guix. If not, see <http://www.gnu.org/licenses/>.
(define-module (guix build http) (define-module (guix build http)
#:use-module (web client)
#:use-module (web uri) #:use-module (web uri)
#:use-module (web client)
#:use-module (web response)
#:use-module (rnrs io ports) #:use-module (rnrs io ports)
#:use-module (srfi srfi-11) #:use-module (srfi srfi-11)
#:export (http-fetch)) #:export (http-fetch))
...@@ -83,8 +84,14 @@ (define (http-fetch url file) ...@@ -83,8 +84,14 @@ (define (http-fetch url file)
((connection) ((connection)
(open-connection-for-uri uri)) (open-connection-for-uri uri))
((resp bv) ((resp bv)
(http-get uri #:port connection #:decode-body? #f))) (http-get uri #:port connection #:decode-body? #f))
(call-with-output-file file ((code)
(lambda (p) (response-code resp)))
(put-bytevector p bv)))) (if (= 200 code)
file) (begin
(call-with-output-file file
(lambda (p)
(put-bytevector p bv)))
file)
(error "download failed" url
code (response-reason-phrase resp)))))
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