From debbugs-submit-bounces@debbugs.gnu.org Sun Apr 10 09:44:58 2022 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 To: 54836@debbugs.gnu.org Subject: [PATCH 3/3] http-client: Factor out open-connection*, rename variables. 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 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 54836 Cc: Attila Lendvai X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) 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) -- 2.34.0