From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +KzWM8XEA2KWQAAAgWs5BA (envelope-from ) for ; Wed, 09 Feb 2022 14:42:29 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id cMU6MMXEA2IQ9wAAauVa8A (envelope-from ) for ; Wed, 09 Feb 2022 14:42:29 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 766D91432A for ; Wed, 9 Feb 2022 14:42:29 +0100 (CET) Received: from localhost ([::1]:52166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHnEq-0005vm-8t for larch@yhetil.org; Wed, 09 Feb 2022 08:42:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHmy9-0004di-TO for guix-patches@gnu.org; Wed, 09 Feb 2022 08:25:13 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:56281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHmxy-0004EI-O7 for guix-patches@gnu.org; Wed, 09 Feb 2022 08:25:11 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nHmxy-00076N-4k; Wed, 09 Feb 2022 08:25:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53818] [PATCH v3 2/7] http-client: Make 'http-fetch/cached' take '#:headers' 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:25:02 +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.164441307427228 (code B ref 53818); Wed, 09 Feb 2022 13:25:02 +0000 Received: (at 53818) by debbugs.gnu.org; 9 Feb 2022 13:24:34 +0000 Received: from localhost ([127.0.0.1]:50171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHmxV-000755-Uf for submit@debbugs.gnu.org; Wed, 09 Feb 2022 08:24:34 -0500 Received: from h178-251-242-94.cust.a3fiber.se ([178.251.242.94]:44848 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nHmxT-00074p-T1 for 53818@debbugs.gnu.org; Wed, 09 Feb 2022 08:24:33 -0500 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoctocell.xyz; s=mail; t=1644413066; bh=akL6Y2/X0FEbcEKilz3Py/WZu638Uz61mmUyiLjh3JI=; h=From:To:Subject:In-Reply-To:References:Date; b=Dt5VdwuUzo6NSlpEs+tX+W5Q+gBzb9YIk5rBf74CodrO16s/bgB6nDCuUOFwAA8KH lz0VBuVC0xBFBxyR8UcM4iWuch4cLNdk8k7EIhHwsmXja+Hy6+bE0i43pUVIyS/xsb MHYuaHDo7txOjrWiwGBwgWNoh9GJ2z9Zv66xqfxc= In-Reply-To: References: Message-Id: <0ad40732008ce4a9214df154d431741c90e0f128.1644412701.git.public@yoctocell.xyz> Date: Wed, 09 Feb 2022 14:24:25 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644414149; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=akL6Y2/X0FEbcEKilz3Py/WZu638Uz61mmUyiLjh3JI=; b=YUk4lqbUhXtxw3ibQ8emTggZYfNIJUWSJypPhY+jBMDQn/94WTmCMYVVt8a608ZvHFFuBS nevNbqC1pYfYqYhzzbBKf8ZzlRAnWeCT+TMFIb2fkIWREgALwfA/2Tirv3wRNxWtdZuhig LPWJx9rg4Hd5vXLKF2a6h3/Tr+J/ofh+cpatefnbc+e86WDaSaohfM/SanfzHzjL/r68wC I0kJYJmCJQ2YyfP8++G2qIa+bXc4YoS0AY7yk0x/atV6jIkWJ4Id57wkFu5Hpj+fOR3OIV qylVrynrd4mUjhdAG2ux9BrlTJownOmX7BnaF/M+/ivC+kOh5Leue2WOldcrAA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644414149; a=rsa-sha256; cv=none; b=DopkoB6XimgTZfUk8q2KOcWv/fuuiSsDgJ8asqKE0DygC+Cc72P+zHqLJ9scfJKmOwemdQ 5D+t9uwTM0iAibYuE1wsTp9Fv1V+B4ce/+lyzOFgMk9sfg6+nhYTuvlQfiWXTzKZjLSHXl IeHSLKIgWk3xigtYaH8GFA2lJMwNmIRZj18BYQhphrgdNsMW4W30EX+Np/mGfs5YM7i0EU TiDG4pLrsVK5Q1xloCSlE4AUwSBdu5HrLTs0WL6IN4PqvX5onccyJxPLlKOrhwEYJZJyKH 0nsjdBnLMeK6SadyowSZ98cgaHAseNgPRu3zqD7rqZHv6o1dVMQcCMx1U8g4zQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=Dt5VdwuU; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.83 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=Dt5VdwuU; dmarc=fail reason="SPF not aligned (relaxed)" header.from=yoctocell.xyz (policy=none); spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 766D91432A X-Spam-Score: -1.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: fAha3tIYt0GV * guix/http-client.scm (http-fetch/cached): Take =E2=80=98#:headers=E2=80= =99 keyword argument. --- guix/http-client.scm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 10bc278023..058f09852f 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -3,6 +3,7 @@ ;;; Copyright =C2=A9 2015 Mark H Weaver ;;; Copyright =C2=A9 2012, 2015 Free Software Foundation, Inc. ;;; Copyright =C2=A9 2017 Tobias Geerinckx-Rice +;;; Copyright =C2=A9 2022 Xinglu Chen ;;; ;;; This file is part of GNU Guix. ;;; @@ -283,9 +284,11 @@ (define* (http-fetch/cached uri #:key (ttl (%http-cach= e-ttl)) text? (write-cache dump-port) (cache-miss (const #t)) (log-port (current-error-port)) - (timeout 10)) + (timeout 10) + (headers '((user-agent . "GNU Guile")))) "Like 'http-fetch', return an input port, but cache its contents in -~/.cache/guix. The cache remains valid for TTL seconds. +~/.cache/guix. The cache remains valid for TTL seconds. HEADERS is an al= ist +of extra HTTP headers. The cache time will automatically be added to HEAD= ERS, so there is no need to specify it. =20 Call WRITE-CACHE with the HTTP input port and the cache output port to wri= te the data to cache. Call CACHE-MISS with URI just before fetching data from @@ -300,8 +303,8 @@ (define cache-time (and cache-port (stat:mtime (stat cache-port)))) =20 - (define headers - `((user-agent . "GNU Guile") + (define headers* + `(,@headers ,@(if cache-time `((if-modified-since . ,(time-utc->date (make-time time-utc 0 cache-time)))) @@ -316,7 +319,7 @@ (define headers (raise c)))) (let ((port (http-fetch uri #:text? text? #:log-port log-port - #:headers headers #:timeout timeout))) + #:headers headers* #:timeout timeout))) (cache-miss uri) (mkdir-p (dirname file)) (when cache-port --=20 2.34.1