[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#53818] [PATCH v2 4/7] import: json: Make 'json-fetch' take '#:cache
From: |
Xinglu Chen |
Subject: |
[bug#53818] [PATCH v2 4/7] import: json: Make 'json-fetch' take '#:cached?' argument. |
Date: |
Mon, 07 Feb 2022 10:07:01 +0100 |
* json.scm (json-fetch): Add ‘#:cached?’ keyword argument.
---
guix/import/json.scm | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/guix/import/json.scm b/guix/import/json.scm
index 0c98bb25b8..6f88353659 100644
--- a/guix/import/json.scm
+++ b/guix/import/json.scm
@@ -3,6 +3,7 @@
;;; Copyright © 2015, 2016 Eric Bavier <bavier@member.fsf.org>
;;; Copyright © 2018, 2019 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
+;;; Copyright © 2022 Xinglu Chen <public@yoctocell.xyz>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -37,17 +38,22 @@ (define-module (guix import json)
(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"))))
+ #:key
+ (headers `((user-agent . "GNU Guile")
+ (Accept . "application/json")))
+ cached?)
"Return a representation of the JSON resource URL (a list or hash table), or
#f if URL returns 403 or 404. HEADERS is a list of HTTP headers to pass in
-the query."
+the query. If CACHED? is #t, 'http-fetch/cached' will be used to fetch URL."
(guard (c ((and (http-get-error? c)
(let ((error (http-get-error-code c)))
(or (= 403 error)
(= 404 error))))
#f))
- (let* ((port (http-fetch url #:headers headers))
+ (let* ((port ((if cached?
+ http-fetch/cached
+ http-fetch)
+ url #:headers headers))
(result (json->scm port)))
(close-port port)
result)))
--
2.34.1
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., (continued)
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Xinglu Chen, 2022/02/07
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Maxime Devos, 2022/02/07
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Maxime Devos, 2022/02/07
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Xinglu Chen, 2022/02/08
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Maxime Devos, 2022/02/08
- [bug#53818] [PATCH v2 5/7] import: Add 'repology' updater., Xinglu Chen, 2022/02/09
[bug#53818] [PATCH v2 3/7] http-client: 'http-fetch/cached' accepts a string or a <uri>., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 2/7] http-client: Make 'http-fetch/cached' take '#:headers' argument., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 6/7] gnu: xorg-server-xwayland: Set 'repology-name' property., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 7/7] gnu: xorg-server-xwayland: Prepare for cross-compilation., Xinglu Chen, 2022/02/07
[bug#53818] [PATCH v2 4/7] import: json: Make 'json-fetch' take '#:cached?' argument.,
Xinglu Chen <=
[bug#53818] [PATCH v3 0/7] Add Repology updater, Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 2/7] http-client: Make 'http-fetch/cached' take '#:headers' argument., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 3/7] http-client: 'http-fetch/cached' accepts a string or a <uri>., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 1/7] upstream: Sort list of updaters., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 4/7] import: json: Make 'json-fetch' take '#:http-fetch' argument., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 7/7] gnu: xorg-server-xwayland: Prepare for cross-compilation., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 6/7] gnu: xorg-server-xwayland: Set 'repology-name' property., Xinglu Chen, 2022/02/09
- [bug#53818] [PATCH v3 5/7] import: Add 'repology' updater., Xinglu Chen, 2022/02/09
[bug#53818] [PATCH 0/3] Add Repology updater, Ludovic Courtès, 2022/02/08