From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cBdTB+JuuGOaSgEAbAwnHQ (envelope-from ) for ; Fri, 06 Jan 2023 19:56:34 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id WOxFB+JuuGPcbwAAauVa8A (envelope-from ) for ; Fri, 06 Jan 2023 19:56:34 +0100 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 BBDEF3C72B for ; Fri, 6 Jan 2023 19:56:33 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDrsu-00014b-OF; Fri, 06 Jan 2023 13:56:08 -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 1pDrso-0000y2-Rk for guix-patches@gnu.org; Fri, 06 Jan 2023 13:56:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pDrso-0007bf-JS for guix-patches@gnu.org; Fri, 06 Jan 2023 13:56:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pDrso-0008Kr-Ao for guix-patches@gnu.org; Fri, 06 Jan 2023 13:56:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH v4 1/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: Fri, 06 Jan 2023 18:56: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: moreinfo patch To: 54836@debbugs.gnu.org Cc: Attila Lendvai Received: via spool by 54836-submit@debbugs.gnu.org id=B54836.167303132331971 (code B ref 54836); Fri, 06 Jan 2023 18:56:02 +0000 Received: (at 54836) by debbugs.gnu.org; 6 Jan 2023 18:55:23 +0000 Received: from localhost ([127.0.0.1]:55853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDrsA-0008Ja-L1 for submit@debbugs.gnu.org; Fri, 06 Jan 2023 13:55:23 -0500 Received: from mail-wm1-f44.google.com ([209.85.128.44]:35718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDrs9-0008JK-6b for 54836@debbugs.gnu.org; Fri, 06 Jan 2023 13:55:21 -0500 Received: by mail-wm1-f44.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so4209884wms.0 for <54836@debbugs.gnu.org>; Fri, 06 Jan 2023 10:55:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=vJTQ9xGFt0HQmYzZlHtezoP0VLL0lbhtb8NomwgTRuY=; b=CxnO4LiZ8YrrjRgU/hMYZoSAVkVo+2lf7qq8fSeOeMhZkykNVsRCpC7dDKr6XJkyx0 4AxsxDs3OY1/dOl6ebjWJ8Mz6YvfbU7yFsU0sRy9TK+reB6NawyedDUzygeleeSio3zE urWBmrw49ciiT7YxgG2PS5Y4nGsjfbEO1YVw4kIOIMH1sl1g8A7AqCLXi/NDoisMfVMD R4LcSnAMk/rKzuiS9gPWrrfYXIRzshc2gWT0DFA/54sHG8wAlFp0OJLYNc4Ntb9oLSRH MrW/ZsP/FZ3U3hjrrfEGIJZWdtmjDNSabO+exNiOASxdzcfZ/jgfGjoBafRReW6fOJ9E th1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vJTQ9xGFt0HQmYzZlHtezoP0VLL0lbhtb8NomwgTRuY=; b=K26TpWw4smVjub3r2dJacLtEdoHCtE5gChfdRnBKZWTdLWkw7iHfZ946XHQg9uh/zt uuO8wjVWyFKzoPEhzf01sFzMH0E9j2RVWFa2NpWsNjjp6rzuWBtbz2XVU0gngGA8X446 e8C0aiUhZ4tLAcwn11PnK2QlPpz09d0xz1jEvgMmmpyXHSGkvfgn6+yfvK4lJmyE0Jbt V6ApN+jiiL5dg8y3tuFRu8yC/Yus5KZsUgefCXnirn8a9tlAXubEU6fE+Ejrm2OXG4/8 M2AWw+vhPslb+XY/F4P29VybpbXqfE1imBa94vI1w2q4WiEsIfym6jtbrvhm2Xu4wu5p cs8A== X-Gm-Message-State: AFqh2kqWtwsNMOw8k754RCtuHEAaIMOS8iZFJ1TNL363zcTzALLbIo6h x34MqDUX+GhOe3zuFLLB9fyAbIx2lQg= X-Google-Smtp-Source: AMrXdXt9dJga8cUlTOJu/HFzDTycGU8ycDS+cyrR/jSxCB8wpnOEKvuynh/ohKNq7CumZrrv5DLIYQ== X-Received: by 2002:a05:600c:4e09:b0:3d4:5741:af9b with SMTP id b9-20020a05600c4e0900b003d45741af9bmr43947192wmq.0.1673031315214; Fri, 06 Jan 2023 10:55:15 -0800 (PST) Received: from lelap.lan (catv-80-98-247-145.catv.fixed.vodafone.hu. [80.98.247.145]) by smtp.gmail.com with ESMTPSA id h8-20020a05600c350800b003d990372dd5sm7988352wmq.20.2023.01.06.10.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 10:55:14 -0800 (PST) From: Attila Lendvai Date: Fri, 6 Jan 2023 19:46:54 +0100 Message-Id: <20230106184654.28037-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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1673031393; 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=vJTQ9xGFt0HQmYzZlHtezoP0VLL0lbhtb8NomwgTRuY=; b=kMLQ4lY5AFGJACjUPI1mYlMnsj4oUiRQ9zhBPhWszLpnX1kf+0OrjZGnkhQLJW9Xc59yw4 IrNTlbr1/LP/41quZn5nrtt1/DNGsMoO8tG6MlV2SDNjZfna7mA/cerNg7U/jw5A1Rj+8H gWffE6LCiQhJv3TXr3+otTi064e1Ao+vVtfsCxpNT7nzEuVxPoGmIg7JVjroKh7dfpGy3d kzTbdSYQ5L4Ad6pLBqQCLJM9ZVpBr1ZfhCjjPLEqukEPrDjVS/GhYmPPsMwm/r6BB/7q/B SM7WYnVxTB/+YaRzBtWjhPGKFLhhBhoqEY5ApgBczxld7ohr1or2pZORgqcYlQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=CxnO4LiZ; 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"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1673031393; a=rsa-sha256; cv=none; b=fe0K8tspkYqXHil3H+so7/wJFORgFl8PPOSA95nxeG9aWRXSkVwr6eDcB0pwFik7AIxniy vmT9gpo1RjXlcritMKDuGimoNGZ/gTDJd/c6DzAEL56rx/3H40pmmKOB56fKtCQJwh/wtA /JjTWLZnqBYC0AQO7w8NAmWxctZ/sBnwB3baSI7HjvjLAaxoAQy8c2r3IiwJVxCXKwm7hb elgI4XWDoxCBOX7+iFbmkIto7kLPalt0PjM+ZKvgnPjRWHjGC31wQst8VLt2Dr0RHtlT2h B003Fce5IyD6h2cC/T+NCzF+edS+L3sV+IXKz1otp6NUY/KqX3ZbH/O7Esyqmw== X-Spam-Score: 2.44 X-Migadu-Queue-Id: BBDEF3C72B Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=CxnO4LiZ; 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"; dmarc=none X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: 2.44 X-TUID: 6xsTU8xluBrf 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. --- i'm (re)sending the two commits that are sitting in my local branch. i freshly rebased them. the conlusion was to not add the accept-all-response-codes? argument, and accordingly i have added a duplicate of http-fetch into the go importer. my fix was applied by Ludo in his own commit. this is why the 3 commits got reduced to one. i'm only proposing to push the first patch. what the second one does was rejected by Ludo. ratinale for the first patch: it renames variables in a way that is less confusing for the programmer, and hence helps avoiding mistakes that i have fixed in my first original commit. an uri and an uri* variable in the same lexical scope is simply calling for mistakes... 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 9138a627ac..2d48a882e1 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