diff options
author | Marius Bakke <mbakke@fastmail.com> | 2018-08-25 16:44:07 +0200 |
---|---|---|
committer | Marius Bakke <mbakke@fastmail.com> | 2018-08-25 16:44:07 +0200 |
commit | 839167ff9d74fc490b32f6a197591964f73b65e5 (patch) | |
tree | d193bfad7c9ef5597c5cd7d2ea25fd007d01f88a /guix/import/json.scm | |
parent | 27c1df05a866b639a61e16d48b3f2da8fa5eb767 (diff) | |
parent | 030c912616c8ee1595218e304460041bcb4f1ceb (diff) | |
download | guix-patches-839167ff9d74fc490b32f6a197591964f73b65e5.tar guix-patches-839167ff9d74fc490b32f6a197591964f73b65e5.tar.gz |
Merge branch 'staging' into core-updates
Diffstat (limited to 'guix/import/json.scm')
-rw-r--r-- | guix/import/json.scm | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/guix/import/json.scm b/guix/import/json.scm index 3f2ab1e3ea..4f96a513df 100644 --- a/guix/import/json.scm +++ b/guix/import/json.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014 David Thompson <davet@gnu.org> ;;; Copyright © 2015, 2016 Eric Bavier <bavier@member.fsf.org> +;;; Copyright © 2018 Ludovic Courtès <ludo@gnu.org> ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,17 +26,20 @@ #:export (json-fetch json-fetch-alist)) -(define (json-fetch url) +(define* (json-fetch url + ;; Note: many websites returns 403 if we omit a + ;; 'User-Agent' header. + #:key (headers `((user-agent . "GNU Guile") + (Accept . "application/json")))) "Return a representation of the JSON resource URL (a list or hash table), or -#f if URL returns 403 or 404." +#f if URL returns 403 or 404. HEADERS is a list of HTTP headers to pass in +the query." (guard (c ((and (http-get-error? c) (let ((error (http-get-error-code c))) (or (= 403 error) (= 404 error)))) #f)) - ;; Note: many websites returns 403 if we omit a 'User-Agent' header. - (let* ((port (http-fetch url #:headers '((user-agent . "GNU Guile") - (Accept . "application/json")))) + (let* ((port (http-fetch url #:headers headers)) (result (json->scm port))) (close-port port) result))) |