From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id YsSCMSfxAGIRHgAAgWs5BA (envelope-from ) for ; Mon, 07 Feb 2022 11:15:03 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id IG5ALCfxAGK4qwAAauVa8A (envelope-from ) for ; Mon, 07 Feb 2022 11:15:03 +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 3A9D33D78E for ; Mon, 7 Feb 2022 11:15:03 +0100 (CET) Received: from localhost ([::1]:33874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH12z-00029i-Q5 for larch@yhetil.org; Mon, 07 Feb 2022 05:15:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH00B-00068E-OV for guix-patches@gnu.org; Mon, 07 Feb 2022 04:08:04 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:47041) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nH00A-0004Jj-Kq for guix-patches@gnu.org; Mon, 07 Feb 2022 04:08:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nH00A-0002ur-08; Mon, 07 Feb 2022 04:08:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#53818] [PATCH v2 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: Mon, 07 Feb 2022 09:08: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.164422483911116 (code B ref 53818); Mon, 07 Feb 2022 09:08:01 +0000 Received: (at 53818) by debbugs.gnu.org; 7 Feb 2022 09:07:19 +0000 Received: from localhost ([127.0.0.1]:40925 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGzzT-0002t1-1e for submit@debbugs.gnu.org; Mon, 07 Feb 2022 04:07:19 -0500 Received: from h178-251-242-94.cust.a3fiber.se ([178.251.242.94]:55268 helo=mail.yoctocell.xyz) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGzz9-0002re-7U for 53818@debbugs.gnu.org; Mon, 07 Feb 2022 04:07:03 -0500 From: Xinglu Chen DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yoctocell.xyz; s=mail; t=1644224813; bh=akL6Y2/X0FEbcEKilz3Py/WZu638Uz61mmUyiLjh3JI=; h=From:To:Subject:In-Reply-To:References:Date; b=daLPuNj11/d24yygmKE0YHg9U889uuPeRQdfSAINyfd5ZNVeJ/4wOrpqB2gi3Efki a4MZkFUsxvUPiNcK5RGFo0P7QqjCswJlfltMdkYv4+ROuiUAreSuxPRNFmSfFgnUfM NFwbRl5nreY3hiric5qlJskiU2c6fMyVBrCAlR2g= In-Reply-To: References: Message-Id: Date: Mon, 07 Feb 2022 10:06:52 +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=1644228903; 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=N+dGyRkY5pJFJzgzbGs3Y4uoACJwY20NmEM6hwFY+SFkqN5G9v8lmZEeYUTkYgHQ8dvBn4 u9Gb6P5eAUisZbn9cIcSp0jsjetbZdsg7vCajQmxvZkBdM7kXpE+H0tVsid/5bHgsilU8B f2XCojJ77om5kygVFdmkcZeThaM6FQGpAGDIbTEWnIPAjaOmuM0klPioV3JhxPsbpGnUYU X8sPamdjBYwX+njgn2BODiLCzaC6RMafMOvKXGZqrfcGG326OZAE+M8AUJE4B8YTfcH/6W FhI1zl/8BUfhbPBH3uYxKrreB0sJkbyf6GNBKw+1Km+G3lDOn3Hmlx32rAWzCg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644228903; a=rsa-sha256; cv=none; b=nbEXkUtSoxM8FvEFU7Hvub1Ur6u2PwPgL9e6BM/7doVq0wTEGYvP84MmJxZO27NTSr/m/1 1Y0cdEir5flDJTW8ErgLAFOlZI5CLGPZzTBkkfzGym7LqH/lRE4CnAx3WEiu/VKXT50Fd4 yOe29+TPNgFJ3gJSO+r8LY+dw2EFwPuk+bn0Rne2MS2Oy3c+gu9kmLv7xDRZPi7NqGJPqK X7v3CtOXS7qUyawL4MI+Hy5rr9unrGyFJbkrVPSnNpmGhfQvMSStGj9Qwc+VaBiY/fdySK UX8kPNs8a6I7LrS+ZFZlNUA+PH5ou5wtcsyTdpVGhMDUbrb97mWnLK+MazJ7HA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=yoctocell.xyz header.s=mail header.b=daLPuNj1; 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=daLPuNj1; 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: 3A9D33D78E X-Spam-Score: -1.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: YjuNliuW1mqV * 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