From patchwork Sun Apr 10 13:41:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38484 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 6691927BBEA; Sun, 10 Apr 2022 14:45:27 +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 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 E3C2227BBE9 for ; Sun, 10 Apr 2022 14:45:26 +0100 (BST) Received: from localhost ([::1]:59666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXsc-00040Y-1O for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 09:45:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXsE-00040A-GA for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXsE-0004Oa-7X for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXsE-0000ze-1u for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH v2 1/3] http-client: Added accept-all-response-codes? argument. References: <20220410133431.30058-1-attila@lendvai.name> In-Reply-To: <20220410133431.30058-1-attila@lendvai.name> Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 10 Apr 2022 13:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54836 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54836@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 54836-submit@debbugs.gnu.org id=B54836.16495982923765 (code B ref 54836); Sun, 10 Apr 2022 13:45:01 +0000 Received: (at 54836) by debbugs.gnu.org; 10 Apr 2022 13:44:52 +0000 Received: from localhost ([127.0.0.1]:39762 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs4-0000ye-45 for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:52 -0400 Received: from mail-ed1-f54.google.com ([209.85.208.54]:40481) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs1-0000yL-Sr for 54836@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:50 -0400 Received: by mail-ed1-f54.google.com with SMTP id v4so1720411edl.7 for <54836@debbugs.gnu.org>; Sun, 10 Apr 2022 06:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=++3ok8LxQxAfqdef0Oab922kDhcqy0nEv2t3ab3GQ7M=; b=df/eAmBjq/hvxwW4yIHjwMvknW8A++InQJEwxvR1Y722E6XFbaS41yqcMLq/NXfbni U/2heogZc9R+Kq8AbqmAY1NPkUWkh1SFhJ35ygX/InXljBtqSaZSdkjdW8yeGOpfKKSQ X3GKbnbcmnQVL0ElcmTxX5kI/KHSCQmlaRuSAce3EvKPr01WemwiGcCNSkXKqwZiOkyk UNWWL+cFuGgr8AXwltUDUrAs2ugBzntwg4OO0OeIgM2h8+pnmzKbtyQfaByWyewJalRD RQwHkP6It7y0BjEMc87UQ+KqbD918PsvIqDFFbZ3qpAtMze/J8Shz92TVB6gaRDOgIWN XIDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=++3ok8LxQxAfqdef0Oab922kDhcqy0nEv2t3ab3GQ7M=; b=pM6nI1qSSJltugXMQ6n+GuATfBF7yDbV2nPbdF09RkBtekY1y+Nqbn3oh2gVCwoJ/R re9xeVRq1JUUF4mzTvFmMrpqvs7Swy0AqLyWVxuz4zch16D+drBdmAbd7cKb9EoYpYBR gzOQSWCoj+sqae8wfogrsOWlL07d8e1WZ8qcyQjOGxGvR0ar8wHbxq3VqWrKE47xqAqe qAbGBkVWYQnZyiqZLfFP1JMIIUW+NBc10qv4eGPYj9lpkn37NK7OaDE/2SQOP7igVasc BrVON1E8ndWvGiq3EwfW60yPhDM4Ts3dzFtcF1NnIgUz8IBBb2KYJmjtv3/FqmOArz/i 6XAw== X-Gm-Message-State: AOAM533Bi08kT1UUf0Eon4bVQWE9FNtANweyOH5vsJGIgMV5ABe0GA+N ynDZk+r9TPwyUQw0LFABHjnFsVlsDag= X-Google-Smtp-Source: ABdhPJwAuLJ3qNC+BxCUXXzFWU34Ttkhy5wcwP4xrhUHjaWikyj92i1O3diaJll1zqZz3/CNy8ydig== X-Received: by 2002:aa7:c612:0:b0:41d:7ad7:4a4d with SMTP id h18-20020aa7c612000000b0041d7ad74a4dmr820442edq.125.1649598283998; Sun, 10 Apr 2022 06:44:43 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id p24-20020a056402045800b0041614c8f79asm13232201edw.88.2022.04.10.06.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:44:43 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:41:13 +0200 Message-Id: <20220410134114.371-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 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 is needed when dealing with golang packages, as per: https://golang.org/ref/mod#vcs-find A page may return 404, but at the same time also contain the sought after `go-import` meta tag. An example for such a project/page is: https://www.gonum.org/v1/gonum?go-get=1 It's not enough to just handle the thrown exception, because we need to be able to get hold of the fetched content, too. * guix/http-client.scm (http-fetch): Add #:accept-all-response-codes? keyword argument defaulting to #f, and implement the logic. --- oops, resending because the first version doesn't apply on master. v2 also contains an initial commit, a feature addition that is needed for my (soon to be sent) improvements to the go importer. guix/http-client.scm | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 143ed6de31..8a5b3deecd 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -82,7 +82,8 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t) (verify-certificate? #t) (headers '((user-agent . "GNU Guile"))) (log-port (current-error-port)) - timeout) + timeout + (accept-all-response-codes? #f)) "Return an input port containing the data at URI, and the expected number of bytes available or #f. If TEXT? is true, the data at URI is considered to be textual. Follow any HTTP redirection. When BUFFERED? is #f, return an @@ -99,7 +100,9 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t) Write information about redirects to LOG-PORT. -Raise an '&http-get-error' condition if downloading fails." +When ACCEPT-ALL-RESPONSE-CODES? is false then raise an '&http-get-error' +condition if downloading fails, otherwise return the response regardless +of the reponse code." (define uri* (if (string? uri) (string->uri uri) uri)) @@ -150,18 +153,20 @@ (define uri* verify-certificate? #:timeout timeout))))) (else - (raise (condition (&http-get-error - (uri uri) - (code code) - (reason (response-reason-phrase resp)) - (headers (response-headers resp))) - (&message - (message - (format - #f - (G_ "~a: HTTP download failed: ~a (~s)") - (uri->string uri) code - (response-reason-phrase resp)))))))))))) + (if accept-all-response-codes? + (values data (response-content-length resp)) + (raise (condition (&http-get-error + (uri uri) + (code code) + (reason (response-reason-phrase resp)) + (headers (response-headers resp))) + (&message + (message + (format + #f + (G_ "~a: HTTP download failed: ~a (~s)") + (uri->string uri) code + (response-reason-phrase resp))))))))))))) (define-syntax-rule (false-if-networking-error exp) "Return #f if EXP triggers a network related exception as can occur when From patchwork Sun Apr 10 13:41:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38485 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 ECCE527BBEA; Sun, 10 Apr 2022 14:45: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 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 C4CD427BBE9 for ; Sun, 10 Apr 2022 14:45:28 +0100 (BST) Received: from localhost ([::1]:59712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXsd-000435-TY for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 09:45:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXsF-00040H-2Z for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45872) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXsE-0004R2-Pb for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXsE-0000zr-FS for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH 2/3] http-client: Fix redirection. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 10 Apr 2022 13:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54836 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54836@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 54836-submit@debbugs.gnu.org id=B54836.16495982943779 (code B ref 54836); Sun, 10 Apr 2022 13:45:02 +0000 Received: (at 54836) by debbugs.gnu.org; 10 Apr 2022 13:44:54 +0000 Received: from localhost ([127.0.0.1]:39765 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs6-0000yt-GU for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:54 -0400 Received: from mail-ej1-f44.google.com ([209.85.218.44]:44811) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs5-0000yP-3y for 54836@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:53 -0400 Received: by mail-ej1-f44.google.com with SMTP id u15so7237033ejf.11 for <54836@debbugs.gnu.org>; Sun, 10 Apr 2022 06:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RaDM0VnR0FPTk0OmW6s1pk3D+uH62ATdFz58/3F6nA0=; b=kx4VY2eDyxP9FpHCr4wEyQ1F85PjFSjV489y8RihiNl1jHSMVBc099mZa5MdBKKGAs RL6MFdvhTzt1xua+HRm7uJFVx2zRGTy51HDzi2cYtAOmnLc9lcCd6pHCveJLB42m7XC/ /BZ/mJ3BqITZj/rLBbPZdxkGm5e+3l8eelIIacjLmaID5XoIcBNAJkVo5D3yXwbefzvB gwbNjCq9eOp063wOA31tIbpYPRe5caFguI/X6d1bnlWr+kRguzVR1IwsIJA8T1NDTn96 cxgpTY3wiWb7e76CkYZhTzDQ0gnCeSVseOcOVdMp4QzAiX2Tco5EMga7i3QKxHWY01hj 0ypQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=RaDM0VnR0FPTk0OmW6s1pk3D+uH62ATdFz58/3F6nA0=; b=VndoYD3b+IoeFNqGmiMWbo2z8YFPInm37llxjQ9Rx+6NHlSs+SeUmTENPdOO2QUFrY 0Htg/hDmZ9p/ggt4yv2zkOufAQX0vQsawZm+8lc4azixaJ27w56ZsiJ/1kx7IPPNLgVR 72agg6Pyk7sICGt+wUZy7Q/pNzaXH9w30nLvn33OWsi6huORgGnhQ6x9qGk+5UDb0umq WpLzW+bo1r1HE3LvDYFTwrWgrfBh7Fbvy4iLNL+1dSw7CilucBohPsViqCxZQ1BkKRa/ U7KaG9Vsg0qLZXQMlJrEbY8ZCjF2ovJSQVjijKaeP9+z8y4NcXjXc7xXqXcP7Z0ug0w7 UToQ== X-Gm-Message-State: AOAM531XOMEHn08JZyL6RP1HfVSRfBsB1hJ7VyJ+0FCPjsYB1VbmQqfw X89oPGLZAQgPrcxhxEYrvoBufE1wwQc= X-Google-Smtp-Source: ABdhPJxlVSznoJ1zyzo3ol+Qetw4sPvNn+a/9IKDTb/mXp0n849mQfN5Q1Ows05m/9+NPDLKyGfeIg== X-Received: by 2002:a17:907:72c5:b0:6da:e99e:226c with SMTP id du5-20020a17090772c500b006dae99e226cmr26643875ejc.515.1649598287324; Sun, 10 Apr 2022 06:44:47 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id p24-20020a056402045800b0041614c8f79asm13232201edw.88.2022.04.10.06.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:44:46 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:41:14 +0200 Message-Id: <20220410134114.371-2-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220410134114.371-1-attila@lendvai.name> References: <20220410134114.371-1-attila@lendvai.name> 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 * guix/http-client.scm (http-fetch): Use the right uri variable in case of redirection. --- guix/http-client.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 8a5b3deecd..b8689a22ed 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -148,7 +148,7 @@ (define uri* (or (not (uri-host uri)) (string=? host (uri-host uri))) port) - (open-connection uri* + (open-connection uri #:verify-certificate? verify-certificate? #:timeout timeout))))) From patchwork Sun Apr 10 13:41:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38486 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 74D4C27BBEB; Sun, 10 Apr 2022 14:45:36 +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 autolearn=ham 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 E9DE927BBEA for ; Sun, 10 Apr 2022 14:45:35 +0100 (BST) Received: from localhost ([::1]:60134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXsl-0004LU-3w for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 09:45:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42174) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXsF-00040K-7p for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXsE-0004VZ-VC for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXsE-0000zy-Td for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH 3/3] http-client: Factor out open-connection*, rename variables. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 10 Apr 2022 13:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54836 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54836@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 54836-submit@debbugs.gnu.org id=B54836.16495982983794 (code B ref 54836); Sun, 10 Apr 2022 13:45:02 +0000 Received: (at 54836) by debbugs.gnu.org; 10 Apr 2022 13:44:58 +0000 Received: from localhost ([127.0.0.1]:39768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs9-0000z7-N2 for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:58 -0400 Received: from mail-ed1-f44.google.com ([209.85.208.44]:36483) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs7-0000ya-UW for 54836@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:56 -0400 Received: by mail-ed1-f44.google.com with SMTP id u18so4546392eda.3 for <54836@debbugs.gnu.org>; Sun, 10 Apr 2022 06:44:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Jr3nk6fSgo+JsRrC1wJ6HC4Iz1hEn92rKHFW91BQOa0=; b=n9ApJ5g3i2LTMJU9hqvEaxBY5n/EmF1aOEmLtCTaqILTf54zWyrRKvyc33u3zo2eWN nPLd6WPtGdM16f49O98Jwf2WoEjNKpFvtwgCNI61SKqBdvUEHLXzaZigtk7HrMLQKt7C y9gX9PaXDhxpvCFJRPeP+lLxKBjW/R24ZgEaX1JUO/zXXOhxB2O1kXksH7qXzktSC+En GEA3wlMVd2D9ps82soHq7mRJbdrODTPiqHOdpjoabOZuSr5N9M1AO0PxxvjMOPRq8CBi WpkVhP+G32pGR7XMryC/exROP67c1iSEkxI14yZkFSuUDCo2y5K9cernKeEOh+C6nq/j b6kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=Jr3nk6fSgo+JsRrC1wJ6HC4Iz1hEn92rKHFW91BQOa0=; b=woONAZ/2UXQPt0MxE9jpSGLWpunetlOpG7XJUwruYwUWlobL6FBKdAs83An+mRob0a lI9vfJFyx2rzuefymGv7rcy87itQ3wTQfjQTch7FoLSxSU5FwDn+cTxn9/0Kh4FSh9y7 /cmMykMaPdClVbYg2kNkifyVIq90pWAs4zlq2xBIq6dRzyajRbUnaJY/FroLIcvseQDm Kbfrrk4lUXpRPifuP/I3KhWYg6DN8PeskzJWHE58R5kyXxDeTcRj9zSqKPT3k6Dcr9/m UyBnTDOYEIWAonSMt9J0sbCxNe6XRCTIsYh4pQRpLwH63Ds8Nx+Lj+oEecUz2uKsKw9M X+Zw== X-Gm-Message-State: AOAM532Wa9d/OvkK+kfA5fjnmjHos1rBeuaLMleamCOUJamF2ZCOKrYl NsqIw0mXURxRLJAllBOuvF2QNpcNqlA= X-Google-Smtp-Source: ABdhPJzq79XElT1HcKQYjwqH/t7Xpt51jsKo+3z2MIlcZWmyg7Gn5u8d6nDyYEp3PSRHzspxsEdnKg== X-Received: by 2002:a05:6402:298c:b0:41d:6b63:aa67 with SMTP id eq12-20020a056402298c00b0041d6b63aa67mr7081575edb.42.1649598290300; Sun, 10 Apr 2022 06:44:50 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id p24-20020a056402045800b0041614c8f79asm13232201edw.88.2022.04.10.06.44.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:44:49 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:41:15 +0200 Message-Id: <20220410134114.371-3-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220410134114.371-1-attila@lendvai.name> References: <20220410134114.371-1-attila@lendvai.name> 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 is an idempotent refactor. * guix/http-client.scm (http-fetch): Introduce open-connection*. Rename some variables to turn programmer mistakes into compile errors. --- guix/http-client.scm | 48 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index b8689a22ed..3c5115068d 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -103,15 +103,17 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t) When ACCEPT-ALL-RESPONSE-CODES? is false then raise an '&http-get-error' condition if downloading fails, otherwise return the response regardless of the reponse code." - (define uri* + (define parsed-initial-uri (if (string? uri) (string->uri uri) uri)) - (let loop ((uri uri*) - (port (or port (open-connection uri* - #:verify-certificate? - verify-certificate? - #:timeout timeout)))) - (let ((headers (match (uri-userinfo uri) + (define (open-connection* uri) + (open-connection uri + #:verify-certificate? verify-certificate? + #:timeout timeout)) + + (let loop ((current-uri parsed-initial-uri) + (current-port (or port (open-connection parsed-initial-uri)))) + (let ((headers (match (uri-userinfo current-uri) ((? string? str) (cons (cons 'Authorization (string-append "Basic " @@ -119,10 +121,10 @@ (define uri* (string->utf8 str)))) headers)) (_ headers)))) - (unless (or buffered? (not (file-port? port))) - (setvbuf port 'none)) + (unless (or buffered? (not (file-port? current-port))) + (setvbuf current-port 'none)) (let*-values (((resp data) - (http-get uri #:streaming? #t #:port port + (http-get current-uri #:streaming? #t #:port current-port #:keep-alive? keep-alive? #:headers headers)) ((code) @@ -135,28 +137,26 @@ (define uri* 303 ; see other 307 ; temporary redirection 308) ; permanent redirection - (let ((host (uri-host uri)) - (uri (resolve-uri-reference (response-location resp) uri))) + (let ((host (uri-host current-uri)) + (new-uri (resolve-uri-reference (response-location resp) + current-uri))) (if keep-alive? (dump-port data (%make-void-port "w0") (response-content-length resp)) - (close-port port)) + (close-port current-port)) (format log-port (G_ "following redirection to `~a'...~%") - (uri->string uri)) - (loop uri + (uri->string new-uri)) + (loop new-uri (or (and keep-alive? - (or (not (uri-host uri)) - (string=? host (uri-host uri))) - port) - (open-connection uri - #:verify-certificate? - verify-certificate? - #:timeout timeout))))) + (or (not (uri-host new-uri)) + (string=? host (uri-host new-uri))) + current-port) + (open-connection* new-uri))))) (else (if accept-all-response-codes? (values data (response-content-length resp)) (raise (condition (&http-get-error - (uri uri) + (uri current-uri) (code code) (reason (response-reason-phrase resp)) (headers (response-headers resp))) @@ -165,7 +165,7 @@ (define uri* (format #f (G_ "~a: HTTP download failed: ~a (~s)") - (uri->string uri) code + (uri->string current-uri) code (response-reason-phrase resp))))))))))))) (define-syntax-rule (false-if-networking-error exp)