From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id AEaDBPlxamKQ4wAAbAwnHQ (envelope-from ) for ; Thu, 28 Apr 2022 12:52:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 4L7KBPlxamK3BgAA9RJhRA (envelope-from ) for ; Thu, 28 Apr 2022 12:52:41 +0200 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 AB74D21A26 for ; Thu, 28 Apr 2022 12:52:40 +0200 (CEST) Received: from localhost ([::1]:60762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nk1lG-0001TU-4S for larch@yhetil.org; Thu, 28 Apr 2022 06:52:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nk1MU-0007Wr-Nr for guix-patches@gnu.org; Thu, 28 Apr 2022 06:27:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nk1MU-0007Dh-CA for guix-patches@gnu.org; Thu, 28 Apr 2022 06:27:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nk1MU-0005cq-96 for guix-patches@gnu.org; Thu, 28 Apr 2022 06:27:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH v3] 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: Thu, 28 Apr 2022 10:27: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.165114159121580 (code B ref 54836); Thu, 28 Apr 2022 10:27:02 +0000 Received: (at 54836) by debbugs.gnu.org; 28 Apr 2022 10:26:31 +0000 Received: from localhost ([127.0.0.1]:45459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nk1Ly-0005c0-UP for submit@debbugs.gnu.org; Thu, 28 Apr 2022 06:26:31 -0400 Received: from mail-ej1-f52.google.com ([209.85.218.52]:38536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nk1Lw-0005bj-L5 for 54836@debbugs.gnu.org; Thu, 28 Apr 2022 06:26:29 -0400 Received: by mail-ej1-f52.google.com with SMTP id r13so8637756ejd.5 for <54836@debbugs.gnu.org>; Thu, 28 Apr 2022 03:26:28 -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=zuH42bxUCGQfE/N8m73Ld5cYGlr8bKiTowntEZeMA/c=; b=dmu8hHa7z6LZbhA8N/ngyOLYZ4D2VFajpZDopovFFIObZDF0PLzu8z1CuJ/yiAZZWl HocwfFQfGPK8z5fnF9p/1VgrxtE15CALUV9Z+e3zsEukP90NHTG0fi2m+2V15ArzODKN 4dMAM6ILVKkG2Clk7H+zhcR4bym8zLsuuF9ItNHsTpZNkmkudwebUHGxQ4QM4stp5wgw TWwKecqDX7Q56DMeol4qpwAYvnQMQ7DTLq9k25zDieLRJEqshV8+4KOb5q1AojUKHeib 9sCW2MfX4ZTE4eNkryVq/Y9q8TO4rKypiZjZlkbaifh1SUs6zQ89hp38tWDDPXlMlU3j hBIw== 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=zuH42bxUCGQfE/N8m73Ld5cYGlr8bKiTowntEZeMA/c=; b=obn6tt+ukErqHfqElHIPEx1oI68idklZhcGb60mNQknHpnnYo8pZRsdt95PGbWn/ib Tbq4MAZ6q1wqjW8VoxStJrNxX9+xEgdD75LbiG1eo8GL3MRoQxBv1fZ3j9YSvulqD2+O FORQfo/4Qpw3TRyO4z6+fvFCy8oMfUpwwwA2sSCHtTimwDwJF9UVsonbiPzOtLbqBWwy 8fxfUSV/ebwfeT8jUkKXLuakYSXsb9g+ToKe6D2WJ0lDmLLUa36LV24flOQobdIKlT5S Mce1/1tkdZfD61R3EWAKPlKDl0dUmcuJisXHnMDtyJHURWJU796/8mcRD5tfbgmtLkC4 9dwA== X-Gm-Message-State: AOAM532Fw8TuUefqcaTgzZ0Cam0zzvQ+EVjUJZHDGlFjBQpGXuxZFzIJ ZHIkaWkSb/M4pciMlwZF7sSwbLlKrs8= X-Google-Smtp-Source: ABdhPJzmnVdOoSmOpQY/niIA4+Zb7xlvnu/49S7t3EwNHzkDeKa++VquNQfCJp34woXTMGCQza0Crw== X-Received: by 2002:a17:907:98eb:b0:6f3:ce56:c1a2 with SMTP id ke11-20020a17090798eb00b006f3ce56c1a2mr6740861ejc.173.1651141582668; Thu, 28 Apr 2022 03:26:22 -0700 (PDT) Received: from lelap.local (catv-89-132-245-188.catv.fixed.vodafone.hu. [89.132.245.188]) by smtp.gmail.com with ESMTPSA id v21-20020aa7d815000000b0042617ba63b8sm1313694edq.66.2022.04.28.03.26.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 03:26:22 -0700 (PDT) From: Attila Lendvai Date: Thu, 28 Apr 2022 12:22:34 +0200 Message-Id: <20220428102233.14558-1-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 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" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1651143160; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=zuH42bxUCGQfE/N8m73Ld5cYGlr8bKiTowntEZeMA/c=; b=muEEZGSf6Wh0ALL/fMUatupG8La96EMqc57JVgk1siqG+ETEWVt7OHysj6uuKUbOyX4AlD BSXQg1zKVUA2CqnPT+gjS/DrxWjuGHO0YXfIzMs3S4j11jrJmGYRAj1unk/adE2y9Oipyu r8/q+FCwPYBWrl1O6mUqYe09chH+wSuWfQO1IvzGBLO9HLll1BEFJ4HRfDKz6qOkYKGkd5 mdxik9WR5H0O2DFZLvZrjwvdN3+lOLGb79dDu6YKf9q+g7WUrxOnuANCHcicC7ZrP/CfIt IvU9GKx4wCXmfrmq2A1vHnVTdCciRcuN6F1gsS+WixfkTXlJoOZ0ksxlCNvQhQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1651143160; a=rsa-sha256; cv=none; b=sLK97NQbiZikxP2IGZJkNEKxVoH/ZZZxM0ATwgCZt67TRn1sFuHKiZKmbIHL6AIRCAxfR+ RES7qxUNEv4C1e91GbdSqSQo/g2JpVmpc7rvsZ5al6XMhJKHjbdzfAXv9RGU92P7UReABi Nkv8WQib2GVwqlyWHujJAScJAdhfwME+CNFYHRP5GP7Zaj+htbwl0ljxR/GejhSpUB96dj sJUc2kuRzuNuLWYMGBH06OAaf20qyJyhacZpA96+Fv2qGzRmS66NjKC3j0bt2yUb5B0NbN FWzHDbLMKET4jROvAo+KMvzuJOP6NaH7sasPdjKD+6ECpZJrTexbyIpuXljWMw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=dmu8hHa7; dmarc=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: 2.50 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=dmu8hHa7; dmarc=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: AB74D21A26 X-Spam-Score: 2.50 X-Migadu-Scanner: scn1.migadu.com X-TUID: jUHuOIVKgdMi This is an idempotent refactor. * guix/http-client.scm (http-fetch): Introduce open-connection*. Rename some variables to turn programmer mistakes into compile time errors. --- v3: i have reordered the commits so that i can send this idempotent refactor. i think this would be a useful addition to master. it makes the code more defensive against future programmer mistakes, but other than that it shouldn't change the semantics. apply this as you see fit. the rest i'll do in the go importer's module. guix/http-client.scm | 66 ++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index a367c41afa..6c61fd3d8e 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -100,15 +100,17 @@ (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." - (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 " @@ -116,10 +118,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) @@ -132,36 +134,34 @@ (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 (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)))))))))))) + (uri current-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 current-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 -- 2.35.1