From patchwork Wed Feb 9 13:25:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Xinglu Chen X-Patchwork-Id: 37142 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 89CCE27BBEA; Wed, 9 Feb 2022 14:02:19 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, SPF_HELO_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2C2C227BBE9 for ; Wed, 9 Feb 2022 14:02:19 +0000 (GMT) Received: from localhost ([::1]:35970 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHnXx-0007uo-4N for patchwork@mira.cbaines.net; Wed, 09 Feb 2022 09:02:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHmyz-00059Q-4R for guix-patches@gnu.org; Wed, 09 Feb 2022 08:26:06 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:56302) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHmyw-0004h5-14 for guix-patches@gnu.org; Wed, 09 Feb 2022 08:26:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHmyv-00079C-Uh; Wed, 09 Feb 2022 08:26:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53818] [PATCH v3 4/7] import: json: Make 'json-fetch' take '#:http-fetch' argument. Resent-From: Xinglu Chen Original-Sender: "Debbugs-submit" Resent-CC: maximedevos@telenet.be, guix-patches@gnu.org Resent-Date: Wed, 09 Feb 2022 13:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53818 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 53818@debbugs.gnu.org Cc: Maxime Devos X-Debbugs-Original-Xcc: Maxime Devos Received: via spool by 53818-submit@debbugs.gnu.org id=B53818.164441311027352 (code B ref 53818); Wed, 09 Feb 2022 13:26:01 +0000 Received: (at 53818) by debbugs.gnu.org; 9 Feb 2022 13:25:10 +0000 Received: from localhost ([127.0.0.1]:50183 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHmy5-000774-F2 for submit@debbugs.gnu.org; Wed, 09 Feb 2022 08:25:09 -0500 Received: from h178-251-242-94.cust.a3fiber.se ([178.251.242.94]:44870 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHmy3-00076S-FF for 53818@debbugs.gnu.org; Wed, 09 Feb 2022 08:25:08 -0500 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoctocell.xyz; s=mail; t=1644413101; bh=5/6RV8SFyjdKwV6zG391UYkeD0BSMa6Utv9ZFGu2arw=; h=From:To:Subject:In-Reply-To:References:Date; b=sMtleTb2bjyqa0UH/yq2Ag5Vob+Xz5TVDVLN0I5VPmQi2g7gAVti4XYpzH1XNl49J T0uK7ThTkckG9IovAMb+NQ07KwZuOobiXyUlhOkDDGyAJUr5BYPEgR7m3G/SYKJ8yZ gu0OChwcXNW2YexxG3BvgLfQT9zAQvjZ3ylZ7qPc= In-Reply-To: References: Message-Id: Date: Wed, 09 Feb 2022 14:25:01 +0100 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches This will let users of the 'json-fetch' procedure use a custom procedure for fetching the URL, e.g., 'http-fetch/cached'. * json.scm (json-fetch): Add ‘#:http-fetch’ keyword argument. Suggested-by: Maxime Devos --- guix/import/json.scm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/guix/import/json.scm b/guix/import/json.scm index 0c98bb25b8..de7ed60e8d 100644 --- a/guix/import/json.scm +++ b/guix/import/json.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2015, 2016 Eric Bavier ;;; Copyright © 2018, 2019 Ludovic Courtès ;;; Copyright © 2020 Ricardo Wurmus +;;; Copyright © 2022 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -37,11 +38,13 @@ (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"))) + (http-fetch http-fetch)) "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. HTTP-FETCH is the procedure that is used to fetch the JSON data from URL. It should take the URL as an argument and HEADERS as a keyword argument, and return an input port for the JSON data." (guard (c ((and (http-get-error? c) (let ((error (http-get-error-code c))) (or (= 403 error)