From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id sI07E3VQpmBliQAAgWs5BA (envelope-from ) for ; Thu, 20 May 2021 14:05:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yGrwDnVQpmCDYwAA1q6Kng (envelope-from ) for ; Thu, 20 May 2021 12:05:09 +0000 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 F1F27197D9 for ; Thu, 20 May 2021 14:05:08 +0200 (CEST) Received: from localhost ([::1]:41150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljhQK-0003Aq-2y for larch@yhetil.org; Thu, 20 May 2021 08:05:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55816) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljhQE-00037p-9L for guix-patches@gnu.org; Thu, 20 May 2021 08:05:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49948) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljhQD-0004R7-VV for guix-patches@gnu.org; Thu, 20 May 2021 08:05:01 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ljhQD-0003T3-MH for guix-patches@gnu.org; Thu, 20 May 2021 08:05:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47174] [PATCH v3 1/2] guix: Alter http-fetch to return the response. References: <87y2eodxyy.fsf@cbaines.net> In-Reply-To: <87y2eodxyy.fsf@cbaines.net> Resent-From: Christopher Baines Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 20 May 2021 12:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47174 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 47174@debbugs.gnu.org Received: via spool by 47174-submit@debbugs.gnu.org id=B47174.162151225813262 (code B ref 47174); Thu, 20 May 2021 12:05:01 +0000 Received: (at 47174) by debbugs.gnu.org; 20 May 2021 12:04:18 +0000 Received: from localhost ([127.0.0.1]:33259 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ljhPV-0003Rp-Hr for submit@debbugs.gnu.org; Thu, 20 May 2021 08:04:17 -0400 Received: from mira.cbaines.net ([212.71.252.8]:42970) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ljhPT-0003RZ-AH for 47174@debbugs.gnu.org; Thu, 20 May 2021 08:04:16 -0400 Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id 44D0127BC78 for <47174@debbugs.gnu.org>; Thu, 20 May 2021 13:04:14 +0100 (BST) Received: from localhost (localhost [local]) by localhost (OpenSMTPD) with ESMTPA id e84199e6 for <47174@debbugs.gnu.org>; Thu, 20 May 2021 12:04:13 +0000 (UTC) From: Christopher Baines Date: Thu, 20 May 2021 13:04:12 +0100 Message-Id: <20210520120413.21644-1-mail@cbaines.net> X-Mailer: git-send-email 2.31.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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1621512309; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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; bh=8gmV3kQkhsmr3iC3JXV61RptpePfeWhyv86iydQWPI0=; b=jPkDnJqtCCPysisjKlIJIxEVrrxJBkk/v1C6CiIIhDDADAHLFBknf8gguW2NKJnQPrjoGE 2ez9rQRFhMz1bAuyr1L+av+fW/I8EVU3u+8S1Qt9nVoq6dSgAa7exQF/9gWqrmX2Ra3K4g wwe1UwjtgVrQs4e6MR4BYI0H5Gbo5MPyW1AeIQRzNA99XGdJiDgjCoVeTC25PkS65p4pvy JPWZwJomzJZJgFmbvoKhZKCSuWvEEFCvr6o8Vr3BrluGpJQVf3KGj7N9GulCSIqFHokkb4 DhMtAyVurIYHi3WTi0OfSliyhWBX9FirgR3tWlvPM+qhzqOpOJL03DlJkjAmkg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621512309; a=rsa-sha256; cv=none; b=VdO0icse6Yvfdh/X5O1705Ur3U/yz5FQgVcKhzJnsJXeSrXQS3QdJe9RmCGXepGCUO06Pb EKPg87wJdKiA/tC3LKZTtOVRkAId2FqMu+EcyfRH3gKmJU+HVSmVubmvQfe0fjnXm9IKmh Rz8NXkXvqJfkFe3QkwTaFMGjqriS8hdEmq70bt9mdjSRRlZVf1mUR3Ewy3vinVwYFRy+ZQ zF4XrL7dHWfzhI6ixXZn3IOpV6qciaJOJ/qkzB8ZlEiMlrcrNj0DKQbFbxWiN4Zy8sncCb 88KuhUbpUejxz6wQex0rNrZuboDHZ6S4gCZhVbrGP6IjLpONG0Vs5a/RTttXQg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: 2.56 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: F1F27197D9 X-Spam-Score: 2.56 X-Migadu-Scanner: scn0.migadu.com X-TUID: OkLkBjQFTiag Rather than just the port and response-content-length. I'm looking at using the response headers within the substitute script to work out when to close the connection. * guix/http-client.scm (http-fetch): Return the response as the second value, rather than the response-content-length. * guix/build/download-nar.scm (download-nar): Adapt accordingly. * guix/build/download.scm (url-fetch): Adapt accordingly. * guix/scripts/substitute.scm (process-substitution): Adapt accordingly. --- guix/build/download-nar.scm | 5 +++-- guix/build/download.scm | 9 ++++++--- guix/http-client.scm | 12 ++++++------ guix/scripts/challenge.scm | 6 ++++-- guix/scripts/substitute.scm | 12 ++++++++---- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/guix/build/download-nar.scm b/guix/build/download-nar.scm index 867f3c10bb..fbb5d37c0a 100644 --- a/guix/build/download-nar.scm +++ b/guix/build/download-nar.scm @@ -23,6 +23,7 @@ #:autoload (zlib) (call-with-gzip-input-port) #:use-module (guix progress) #:use-module (web uri) + #:use-module (web response) #:use-module (srfi srfi-11) #:use-module (srfi srfi-26) #:use-module (ice-9 format) @@ -101,7 +102,7 @@ success, #f otherwise." ((url rest ...) (format #t "Trying content-addressed mirror at ~a...~%" (uri-host (string->uri url))) - (let-values (((port size) + (let-values (((port resp) (catch #t (lambda () (http-fetch (string->uri url))) @@ -109,7 +110,7 @@ success, #f otherwise." (values #f #f))))) (if (not port) (loop rest) - (begin + (let ((size (response-content-length resp))) (if size (format #t "Downloading from ~a (~,2h MiB)...~%" url (/ size (expt 2 20.))) diff --git a/guix/build/download.scm b/guix/build/download.scm index b14db42352..d2006cc1fd 100644 --- a/guix/build/download.scm +++ b/guix/build/download.scm @@ -22,6 +22,7 @@ (define-module (guix build download) #:use-module (web uri) #:use-module (web http) + #:use-module (web response) #:use-module ((web client) #:hide (open-socket-for-uri)) #:use-module (web response) #:use-module (guix base64) @@ -706,7 +707,7 @@ otherwise simply ignore them." (case (uri-scheme uri) ((http https) (false-if-exception* - (let-values (((port size) + (let-values (((port resp) (http-fetch uri #:verify-certificate? verify-certificate? #:timeout timeout))) @@ -716,9 +717,11 @@ otherwise simply ignore them." #:buffer-size %http-receive-buffer-size #:reporter (if print-build-trace? (progress-reporter/trace - file (uri->string uri) size) + file (uri->string uri) + (response-content-length resp)) (progress-reporter/file - (uri-abbreviation uri) size))) + (uri-abbreviation uri) + (response-content-length resp)))) (newline))) file))) ((ftp) diff --git a/guix/http-client.scm b/guix/http-client.scm index 10bc278023..189535079b 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -81,11 +81,11 @@ (headers '((user-agent . "GNU Guile"))) (log-port (current-error-port)) timeout) - "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 -unbuffered port, suitable for use in `filtered-port'. HEADERS is an alist of -extra HTTP headers. + "Return an input port containing the data at URI, and the HTTP response from +the server. If TEXT? is true, the data at URI is considered to be textual. +Follow any HTTP redirection. When BUFFERED? is #f, return an unbuffered port, +suitable for use in `filtered-port'. HEADERS is an alist of extra HTTP +headers. When KEEP-ALIVE? is true, the connection is marked as 'keep-alive' and PORT is not closed upon completion. @@ -123,7 +123,7 @@ Raise an '&http-get-error' condition if downloading fails." (response-code resp))) (case code ((200) - (values data (response-content-length resp))) + (values data resp)) ((301 ; moved permanently 302 ; found (redirection) 303 ; see other diff --git a/guix/scripts/challenge.scm b/guix/scripts/challenge.scm index 69c2781abb..73103a061b 100644 --- a/guix/scripts/challenge.scm +++ b/guix/scripts/challenge.scm @@ -253,12 +253,14 @@ taken since we do not import the archives." NARINFO." (let*-values (((uri compression size) (narinfo-best-uri narinfo)) - ((port actual-size) + ((port response) (http-fetch uri))) (define reporter (progress-reporter/file (narinfo-path narinfo) (and size - (max size (or actual-size 0))) ;defensive + (max size (or + (response-content-length response) + 0))) ;defensive #:abbreviation (const (uri-host uri)))) (define result diff --git a/guix/scripts/substitute.scm b/guix/scripts/substitute.scm index 8e4eae00b3..96f425eaa0 100755 --- a/guix/scripts/substitute.scm +++ b/guix/scripts/substitute.scm @@ -61,6 +61,7 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (web uri) + #:use-module (web response) #:use-module (guix http-client) #:export (%allow-unauthenticated-substitutes? %reply-file-descriptor @@ -480,10 +481,13 @@ PORT." (uri->string uri)) (warning (G_ "try `--no-substitutes' if the problem persists~%"))) (with-cached-connection uri port - (http-fetch uri #:text? #f - #:port port - #:keep-alive? #t - #:buffered? #f))))) + (let-values (((raw response) + (http-fetch uri #:text? #f + #:port port + #:keep-alive? #t + #:buffered? #f))) + (values raw + (response-content-length response))))))) (else (leave (G_ "unsupported substitute URI scheme: ~a~%") (uri->string uri))))) -- 2.31.1