From patchwork Wed May 18 18:10:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip McGrath X-Patchwork-Id: 39477 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 892E627BBEC; Wed, 18 May 2022 19:14:28 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable 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 0DFE927BBE9 for ; Wed, 18 May 2022 19:14:28 +0100 (BST) Received: from localhost ([::1]:36998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nrOBn-000050-7D for patchwork@mira.cbaines.net; Wed, 18 May 2022 14:14:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nrOAT-0007lT-A9 for guix-patches@gnu.org; Wed, 18 May 2022 14:13:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nrOAT-0005Dr-10 for guix-patches@gnu.org; Wed, 18 May 2022 14:13:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nrOAS-0006M6-TM for guix-patches@gnu.org; Wed, 18 May 2022 14:13:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55030] [PATCH v2 06/34] http-client: Accept '#:headers' in 'http-fetched/cached'. Resent-From: Philip McGrath Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 18 May 2022 18:13:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55030 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55030@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Philip McGrath Received: via spool by 55030-submit@debbugs.gnu.org id=B55030.165289755524238 (code B ref 55030); Wed, 18 May 2022 18:13:04 +0000 Received: (at 55030) by debbugs.gnu.org; 18 May 2022 18:12:35 +0000 Received: from localhost ([127.0.0.1]:33488 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nrO9z-0006Is-It for submit@debbugs.gnu.org; Wed, 18 May 2022 14:12:35 -0400 Received: from mail-vk1-f174.google.com ([209.85.221.174]:35789) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nrO9x-0006IC-VP for 55030@debbugs.gnu.org; Wed, 18 May 2022 14:12:34 -0400 Received: by mail-vk1-f174.google.com with SMTP id e7so1582995vkh.2 for <55030@debbugs.gnu.org>; Wed, 18 May 2022 11:12:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=philipmcgrath.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mPnV0reYPZUEtyICx03sVheX4EBv2lQhaKfqkiBQhsw=; b=giEkkEW+fkk1V9KkLCpuWMOfwnQyQ1ZRW6tNdD/U4svUY8XpxhfbUdmeEM33TJug5H Q7vEZmsXuS6I1BlCeMfKHgo9KiNzNdsrrEgx2iLDEE2/SV3gdHdP50Yrp4ySWCEHVZ0F 1YQsXy0voIbpFu1Kbf8DeDwby7WjORhLiDRKSwhd2v7jC6vv53chQoxfRuqLVPh5IkJD 9dbFb15NmAbyyqJ7zcxzgNSaqKLob6E6l/Dee7+BI6lXq9A/Iuy5+79AQH0AEcKjmUHb mCq5Hx5AWZyBHTdZYWELPKnvdeci0dYXVrVn8/Ql7GaddkOdXDUjWfwgTWRSDzFN/CQ4 0w7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mPnV0reYPZUEtyICx03sVheX4EBv2lQhaKfqkiBQhsw=; b=Uz8SinaBmu6+QPxlg1wAQVdTjH5opX40Xg/rPBUgKOreUeUPfV4dw1VEsU2n3gIesa Eql3s/pH8HagryIMvXblr/QvUhcXsRZ7o4IEH3UdnjLIXqYmIs43UJzXYJo49NPyi3iq wy3OWQVWfYbRbzjO4geCpJHK1mCtE/aytkrZFVWR4zvPCERmiLo4xYx8bQzjkIUJt4Px TOCDJjBfAnSCxPY4f0YhnOl5QNRdLnRaA6Di9eu8HwOyudovV57ZxyYBcSMQcCbGhANp /RbmXRvfvtKu1qQ63Uof4xJZuV+BZcmhpbFVaYvI444mows9gi+3sect7MtBgM7k09TY pJ0A== X-Gm-Message-State: AOAM532jgk95i4AfckOr+dPFwXE8jTanBuGUzBeGIX+64KU76bI13m9n 7DBn3Bt+gw6Zm7T3D7gHviZvrMHSJshHfjqF X-Google-Smtp-Source: ABdhPJyCHGZnSaeC+s8MbmfVinf66/AaXyJlFUSTX+Vlv8tN4LCQXjAU0/8ZWBsFVTqGzkgXnEg0Lg== X-Received: by 2002:a05:6122:1184:b0:356:f6f5:da0c with SMTP id x4-20020a056122118400b00356f6f5da0cmr371589vkn.36.1652897548401; Wed, 18 May 2022 11:12:28 -0700 (PDT) Received: from localhost (c-73-125-98-51.hsd1.fl.comcast.net. [73.125.98.51]) by smtp.gmail.com with UTF8SMTPSA id h12-20020ab02a8c000000b0036280b488c7sm340569uar.16.2022.05.18.11.12.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 May 2022 11:12:28 -0700 (PDT) From: Philip McGrath Date: Wed, 18 May 2022 14:10:53 -0400 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: <20220419232736.272970-1-philip@philipmcgrath.com> 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 Callers can supply alternative headers as with 'http-fetch'. * guix/http-client.scm (http-fetch/cached): Add '#:headers' argument. --- guix/http-client.scm | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index a367c41afa..699f5dfd57 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -296,6 +296,7 @@ (define (cache-file-for-uri uri) #f #f base64url-alphabet)))) (define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? + (headers '((user-agent . "GNU Guile"))) (write-cache dump-port) (cache-miss (const #t)) (log-port (current-error-port)) @@ -307,6 +308,9 @@ (define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? the data to cache. Call CACHE-MISS with URI just before fetching data from URI. +HEADERS is an alist of extra HTTP headers, to which cache-related headers are +added automatically as appropriate. + TIMEOUT specifies the timeout in seconds for connection establishment. Write information about redirects to LOG-PORT." @@ -316,12 +320,12 @@ (define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? (and cache-port (stat:mtime (stat cache-port)))) - (define headers - `((user-agent . "GNU Guile") - ,@(if cache-time - `((if-modified-since - . ,(time-utc->date (make-time time-utc 0 cache-time)))) - '()))) + (define extended-headers + (if cache-time + `((if-modified-since + . ,(time-utc->date (make-time time-utc 0 cache-time))) + ,@headers) + headers)) ;; Update the cache and return an input port. (guard (c ((http-get-error? c) @@ -332,7 +336,8 @@ (define* (http-fetch/cached uri #:key (ttl (%http-cache-ttl)) text? (raise c)))) (let ((port (http-fetch uri #:text? text? #:log-port log-port - #:headers headers #:timeout timeout))) + #:headers extended-headers + #:timeout timeout))) (cache-miss uri) (mkdir-p (dirname file)) (when cache-port