From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id 8OzWKDjrs2XzEgAAqHPOHw:P1 (envelope-from ) for ; Fri, 26 Jan 2024 18:26:16 +0100 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 8OzWKDjrs2XzEgAAqHPOHw (envelope-from ) for ; Fri, 26 Jan 2024 18:26:16 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=EeZ5762w; dmarc=pass (policy=none) header.from=gnu.org; 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" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1706289976; a=rsa-sha256; cv=none; b=AS+cET4s9uy98WZrz7zhil8gQf9Q2smv6nJ+BdCXtTAvDqjbUkS/9JjAU2X8hvt9umzlEd sGSoxzvAOEqj9ir4caMakbjPnDLnaghzvTYV+Rc+qUNiwtDknX8pUHrWcMFhNz+n2lr3Ik 2mSOPt7BdC5TlbOUORvyggN6ZNujtuY8PPKZVzi5kZIreXMd6w/3/bGdAJgeMJ1NK+Hmos Yg++nX4oaOVBpFQnr3JSTjO34O/u9LvdFqae1vU+M7q3skxK5STjx69mrq7fbYqqOpB0ty StYPPSzixha1+ZW2z2rnH7ga3InqaENkokS0jreDGaza7bFcXfafaaSbq7nXMQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=EeZ5762w; dmarc=pass (policy=none) header.from=gnu.org; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1706289976; 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=t3vEQHw0zSebWWR31SkRHVjibufh19E6tE2BvamB6og=; b=WzDnsjuHzsKtKuDrHbT6az1cmCxiPrcBQ9eEmrKet7DI+Nma30bJ2f2O3I0IqHslhLH7GX 2LNJWaI9TSPxBLIEBh6wktRolBK0S9iA+6Gp96SlPJR3cFjaE8PHshEzQpc537aiJbWIdF 0aocx36T8IizGA8DYhQFkoIPykHOGSb9KYuU2vVpENLpPPA71Dgb1xryGoIv+AZj71T8ur T0tbiLPm48sB2O2NNTcHTUz+RDWjCTmidHboMWQu3V9YW5fCxgfG+rgn8wpct1FYwFSo9e hbn9H5hA6NY/4Sd6egD0cqRh2taUT0e9un5bO68SYUmsQVBa2tuAJ+2rsxCZ+A== 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 77E2B2040B for ; Fri, 26 Jan 2024 18:26:15 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTPxo-0005fx-1j; Fri, 26 Jan 2024 12:26:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rTPxm-0005fZ-5d for guix-patches@gnu.org; Fri, 26 Jan 2024 12:25:58 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rTPxl-00006j-Fu; Fri, 26 Jan 2024 12:25:57 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rTPxq-0004gz-QJ; Fri, 26 Jan 2024 12:26:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68741] [PATCH 1/6] swh: =?UTF-8?Q?=E2=80=98vault-fetch=E2=80=99?= follows redirects. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 26 Jan 2024 17:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68741 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68741@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 68741-submit@debbugs.gnu.org id=B68741.170628994517964 (code B ref 68741); Fri, 26 Jan 2024 17:26:02 +0000 Received: (at 68741) by debbugs.gnu.org; 26 Jan 2024 17:25:45 +0000 Received: from localhost ([127.0.0.1]:52654 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rTPxY-0004fN-6M for submit@debbugs.gnu.org; Fri, 26 Jan 2024 12:25:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rTPxU-0004ee-KB for 68741@debbugs.gnu.org; Fri, 26 Jan 2024 12:25:41 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rTPxH-0008Qq-Kx; Fri, 26 Jan 2024 12:25:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=t3vEQHw0zSebWWR31SkRHVjibufh19E6tE2BvamB6og=; b=EeZ5762wiGRfzJe/qQDm dQ+0V843LWdXUyh0r/KoA3gyx3YKCN7NtqqIe17vEl2BdEGKItO/SNhS1dm748aqaseOZ6OSsWRSq SzlxDTiatVnvQwCYPV1/JrI0dAmuCPaaB7QSyy32PWph10mtff9++nLt6ETMfBPVMRyiZCFqZEkS8 PaX/2Smg8tY/BFRF7Y60j2Sn2KrrOhFyzgQPraX5k58+5XlQQ5kMIT9vWk6HbkN/NAUTmyvv4jeGV otvBJ7KDRHabGcjlc9mKAPQx228duBST7sUdrkNvTXgyDGBcOYBczs9iCWXZlPt2hwVYdNsnwA+5t 8MmG7ng2u9w7ww==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 26 Jan 2024 18:25:01 +0100 Message-ID: <8d1ecdcbef60d2643f1aad455e9a2525e6c9d78a.1706287537.git.ludo@gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx10.migadu.com X-Spam-Score: -4.87 X-Migadu-Queue-Id: 77E2B2040B X-Migadu-Spam-Score: -4.87 X-TUID: kI778cpbpFRA Today, URLs like https://archive.softwareheritage.org/api/1/vault/flat/swh:1:dir:84a8b34591712c0a90bab0af604188bcd1fe3153/raw/ redirect to https://swhvaultstorage.blob.core.windows.net/…. This change fixes ‘vault-fetch’ to follow these. * guix/swh.scm (http-get/follow): New procedure. (vault-fetch): Use it instead of ‘http-get*’. Change-Id: Id6b9585a9ce6699a2274b99c9a6d4edda1018b02 --- guix/swh.scm | 52 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/guix/swh.scm b/guix/swh.scm index c7c1c873a2..4e71bdb045 100644 --- a/guix/swh.scm +++ b/guix/swh.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2018-2021, 2024 Ludovic Courtès ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2021 Xinglu Chen ;;; Copyright © 2021 Simon Tournier @@ -583,6 +583,41 @@ (define* (request-cooking id #:optional kind #:key (archive-type 'flat)) json->vault-reply http-post*)) +(define* (http-get/follow url + #:key + (verify-certificate? (%verify-swh-certificate?))) + "Like 'http-get' but follow redirects (HTTP 30x). On success, return two +values: an input port to read the response body and its 'Content-Length'. On +failure return #f and #f." + (define uri + (if (string? url) (string->uri url) url)) + + (let loop ((uri uri)) + (define (resolve-uri-reference target) + (if (and (uri-scheme target) (uri-host target)) + target + (build-uri (uri-scheme uri) #:host (uri-host uri) + #:port (uri-port uri) + #:path (uri-path target)))) + + (let*-values (((response port) + (http-get* uri #:streaming? #t + #:verify-certificate? verify-certificate?)) + ((code) + (response-code response))) + (case code + ((200) + (values port (response-content-length response))) + ((301 ; moved permanently + 302 ; found (redirection) + 303 ; see other + 307 ; temporary redirection + 308) ; permanent redirection + (close-port port) + (loop (resolve-uri-reference (response-location response)))) + (else + (values #f #f)))))) + (define* (vault-fetch id #:optional kind #:key @@ -604,16 +639,11 @@ (define* (vault-fetch id (match (vault-reply-status reply) ('done ;; Fetch the bundle. - (let-values (((response port) - (http-get* (swh-url (vault-reply-fetch-url reply)) - #:streaming? #t - #:verify-certificate? - (%verify-swh-certificate?)))) - (if (= (response-code response) 200) - port - (begin ;shouldn't happen - (close-port port) - #f)))) + (let-values (((port length) + (http-get/follow (swh-url (vault-reply-fetch-url reply)) + #:verify-certificate? + (%verify-swh-certificate?)))) + port)) ('failed ;; Upon failure, we're supposed to try again. (format log-port "SWH vault: failure: ~a~%" -- 2.41.0