From patchwork Sun Apr 10 13:34:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38482 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 1BA4127BBE9; Sun, 10 Apr 2022 14:36:18 +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 D4D3427BBEA for ; Sun, 10 Apr 2022 14:36:15 +0100 (BST) Received: from localhost ([::1]:56108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXji-0001DO-UE for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 09:36:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXia-0000iw-IG for guix-patches@gnu.org; Sun, 10 Apr 2022 09:35:05 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXiZ-00039x-Ii for guix-patches@gnu.org; Sun, 10 Apr 2022 09:35:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXiZ-0000ip-C7 for guix-patches@gnu.org; Sun, 10 Apr 2022 09:35:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH 1/2] 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:35:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54836 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54836@debbugs.gnu.org Cc: Attila Lendvai X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16495976952747 (code B ref -1); Sun, 10 Apr 2022 13:35:03 +0000 Received: (at submit) by debbugs.gnu.org; 10 Apr 2022 13:34:55 +0000 Received: from localhost ([127.0.0.1]:39751 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXiQ-0000iF-Qz for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:34:55 -0400 Received: from lists.gnu.org ([209.51.188.17]:43166) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXiP-0000i8-PH for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:34:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXiP-0000iT-Je for guix-patches@gnu.org; Sun, 10 Apr 2022 09:34:53 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:38514) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXiN-0002zx-Iw for guix-patches@gnu.org; Sun, 10 Apr 2022 09:34:53 -0400 Received: by mail-ed1-x530.google.com with SMTP id z99so6598532ede.5 for ; Sun, 10 Apr 2022 06:34:50 -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=RaDM0VnR0FPTk0OmW6s1pk3D+uH62ATdFz58/3F6nA0=; b=ZDrMB7ub6LoTRoaq2wKgyP4vZfJhfPEl+LqvE30+N3ktF8D/zAq3n6iILQbAcvEhis Iay51p/GiPZPSC7aKxWa9FcowQi4cGjqSRMr74Spld5nwKNt5Y+Nbxi0VwcSzC89vnCx lkicl0omQdoW2aTEkQ/R7gKd/8zggUZEKcuHkd0LOpEsqEzQuEdFke9fpZs31coh86eh KKuTnvyw3nHpwpDC/eQJRwJiQSVydTn4g7HE3Fqo0u/d4dDjMKJGl7gcdA4dp+1xIUwI fRvISpDG71Fs0fjbDzl3Ge8mOyi0ERa3QaNYxN/+Vkmi/iMFf+jPJj7y4tJpYg8WEvig Ihiw== 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=RaDM0VnR0FPTk0OmW6s1pk3D+uH62ATdFz58/3F6nA0=; b=FNYL7x37wD2Uu/nPJrnap7V/vfkozLDyJ5E9Q8CM4DBULca8LyVWnVF5NFp8UshE8F HrFeknBhBNdisL0Uh+2qXimE34hkXyGQVjgH5AQPHFc4+X4D8wyhsQhOMXPSYZc6AYCG 0wNIVcoLGbl/Z97Lny4rTu1fSMAbKFTvr8uKtN7JXCEyWHMW3KTOOU/sFNV+qdl+B2c1 DsbZc3PE+1cRyOGFsCsX3bGVEm2difMMYm29fSVC7k7qh/fbWc2hTMVOz5uF2I0MCmFk ENWgJVAJLpRFQcM4O9zvAczGCxdn7AfV0vslvg/mMZrc38arczTfDBfMucWNcXZz8kbu Qztg== X-Gm-Message-State: AOAM532OpAIK/9/fkvkHvSxdoL7LmMZBsFr1GTjpDuefq0kxTdguyQPO KzQmpfKW8TpBiVu7cooxpl5czlJgsFI= X-Google-Smtp-Source: ABdhPJwO/UxmV7c5puDhOGLEgrZeJd4AQgY9KXaHfP++3BH0kR7zSVdL61nhvvIWX7adCXdpLKIpng== X-Received: by 2002:a05:6402:158b:b0:41d:4a47:cde5 with SMTP id c11-20020a056402158b00b0041d4a47cde5mr11062589edv.312.1649597689404; Sun, 10 Apr 2022 06:34:49 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id r16-20020a056402019000b00418ed60c332sm13473698edv.65.2022.04.10.06.34.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:34:48 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:34:31 +0200 Message-Id: <20220410133431.30058-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=attila.lendvai@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action 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:35:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38483 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 EC68A27BBE9; Sun, 10 Apr 2022 14:37:12 +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 EA22627BBEA for ; Sun, 10 Apr 2022 14:37:09 +0100 (BST) Received: from localhost ([::1]:56378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXkb-0001Rt-43 for patchwork@mira.cbaines.net; Sun, 10 Apr 2022 09:37:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXkU-0001Rk-7W for guix-patches@gnu.org; Sun, 10 Apr 2022 09:37:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXkT-0003Wp-TU for guix-patches@gnu.org; Sun, 10 Apr 2022 09:37:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXkT-0000mF-R4 for guix-patches@gnu.org; Sun, 10 Apr 2022 09:37:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH 2/2] http-client: Factor out open-connection*, rename variables. 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:37: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.16495977732923 (code B ref 54836); Sun, 10 Apr 2022 13:37:01 +0000 Received: (at 54836) by debbugs.gnu.org; 10 Apr 2022 13:36:13 +0000 Received: from localhost ([127.0.0.1]:39758 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXjh-0000l5-5Z for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:36:13 -0400 Received: from mail-ed1-f48.google.com ([209.85.208.48]:43969) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXjf-0000kp-EY for 54836@debbugs.gnu.org; Sun, 10 Apr 2022 09:36:11 -0400 Received: by mail-ed1-f48.google.com with SMTP id b24so15174327edu.10 for <54836@debbugs.gnu.org>; Sun, 10 Apr 2022 06:36:11 -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=Jr3nk6fSgo+JsRrC1wJ6HC4Iz1hEn92rKHFW91BQOa0=; b=c2vY5Tl75Qc6iKH8GQR2wbDDal62rWL8fBm1MNeeE7k1zyNurlMU/y0LMLUGJCy2cp JmoT+RXc3aMgecDPj6QyMzU7G4dgsGwYkuiDwIPvcC2Wch4fv81us6r3umyeZ+iHzxI5 fZBAGmYP0t6NnH+y8zmY49phy1EIeGY/GZ7LR9WKdnXUx8Gu9st1egMj4w3piMYtjMR6 p7cxYvxYeIabMWY8ueo4+BfaGXakqe1LpU9TSB8eVCSmy8EVyR82TI9Z1r5SsqQ3AdKP QjAkPJMpFuRv/XmiF4RROGftWnpKhcG7b6qKaYETbXi92tPHLHYgiTgHKQJPshYctBAT 593g== 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=Jr3nk6fSgo+JsRrC1wJ6HC4Iz1hEn92rKHFW91BQOa0=; b=mrNrj4jjCfggYUdAxQouQ46bvSjYg5JfApPO89XfXq3uZjVCu4+8x1+/4fudvU4xCi k95z1WKE9mDcM0agdmuQdShK/VnLMJrGdCs+geE3dNFRgeWlzNAOVGscLJ7Xp2ppGzo3 GrESrq5HFcWi1sHLrsAk0BLXPsx3p2pVsFBAl+ZwTyZEbE1NbaXwoe5vDPOzNTvvLqHq ThfpmwEDvkC5rTc9tB3v2/Wr66NIgsR9brLCYKL/yCZ7S8B60k8OHrRxfZ1ohZIYLn9H QOeofnDOvLf//3XFpSXlCY8s+HYCuqShwSUUnYTJJiStUl+ON6GHpReFenzvxVQUsBcA 2hsA== X-Gm-Message-State: AOAM533NIaiNbXXj5/8ar0mdsZ0BabZNujfnAZ7anoyfkyLe50BwQGYN paPqeB/MgFNOGhtXpAZDQkGe4ICfyV0= X-Google-Smtp-Source: ABdhPJw4VNPBzXPTjedaWYjm6qzTFaKcB2KyseBkd0gkc/ltTIydp5cbVb6Pz7vmb/p9L9pTPSd8dg== X-Received: by 2002:aa7:d98f:0:b0:41c:bf0f:4c45 with SMTP id u15-20020aa7d98f000000b0041cbf0f4c45mr28718254eds.379.1649597764308; Sun, 10 Apr 2022 06:36:04 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id c4-20020a170906340400b006d077e850b5sm10739645ejb.23.2022.04.10.06.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:36:03 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:35:37 +0200 Message-Id: <20220410133536.30422-2-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 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)