From patchwork Fri Jan 6 18:46:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 45885 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 1A90927BBEB; Fri, 6 Jan 2023 18:56:36 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, URIBL_BLOCKED,URIBL_SBL_A 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 E90D527BBE9 for ; Fri, 6 Jan 2023 18:56:32 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pDrsv-00015f-3Z; Fri, 06 Jan 2023 13:56:09 -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 1pDrsp-0000yH-7s for guix-patches@gnu.org; Fri, 06 Jan 2023 13:56:03 -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-0007br-Vh 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-0008Kz-QX for guix-patches@gnu.org; Fri, 06 Jan 2023 13:56:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH v4 2/2] http-client: Added accept-all-response-codes? argument. 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.167303133231997 (code B ref 54836); Fri, 06 Jan 2023 18:56:02 +0000 Received: (at 54836) by debbugs.gnu.org; 6 Jan 2023 18:55:32 +0000 Received: from localhost ([127.0.0.1]:55856 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDrsK-0008K1-4f for submit@debbugs.gnu.org; Fri, 06 Jan 2023 13:55:32 -0500 Received: from mail-wm1-f43.google.com ([209.85.128.43]:43675) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pDrsH-0008Jl-DO for 54836@debbugs.gnu.org; Fri, 06 Jan 2023 13:55:30 -0500 Received: by mail-wm1-f43.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so1718953wms.2 for <54836@debbugs.gnu.org>; Fri, 06 Jan 2023 10:55:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=Qr17N9iDaCvz5Btvv9P5mNn6eFiXvdSR2vP41aE1txY=; b=GFR1lMpNgGF5tYmWarEKl7YtywjfikFoeHtdUE/3U8Uxyhu43eosrDPe7yKTWdIDQr iuL56vtNrtmg3YAYjBXW3xH7GM0F6hyxqTrzKINljYwNbZc5PzfpomDtopP77Q2eAJfz 98D1gz4bnnWe8U9h38HzRJ1T4qFMZR8e4Yus1YKHJLoBhJu0wQMH7keL2+K3p5YO/TIz qbVXlLKCrHaB3iE9bGUqckR8IyONgYHRSfxs43O6nIXj3axOcNETyrX38hxOFGU6H8VQ 04bcWgNEXzynPYzhrJpgI83Ij9bRj4jzyfQYwKfdFo8cAt3QS23W4mRKhPhLPlP/1q2M nmLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=Qr17N9iDaCvz5Btvv9P5mNn6eFiXvdSR2vP41aE1txY=; b=5+L2k4Y/jH2EbdSt3DOvQR8nR1v50RNspvX5oaEOIKpJeMA/NIDEypGVlkCGlxVLy1 P2ZK06REre1OUuk0gof2jceY0RKKapO4R5yO9I1c217tPElb0lo/2UOXjymRvcp8B+P8 mtg3Xq8mBh96IWFUbBb2xI6BXDyz7knMu9e+2bgF4FxI6osAid52McVEnBmdGMmqRw9A WG5ISP2DuxCfQj/G1ggSGOocs1MNqSvBv9g8ZamzipGi4o6/ryAQijrf0xVxaJHl4axB JEizHIwHo2fjGDvjkh5irRWE3f7uRMqw14YAtpr1BZgGURxj8aBqffl3Tf/gLQkqczL/ Sq4Q== X-Gm-Message-State: AFqh2kqJqpQvMB4NO5hvQNfWD0JwALeQpQmAJIW2zo9FEZf50nc4hOfN +bGFrAozDXUH2avsy1tiT/UYlI+JGOQ= X-Google-Smtp-Source: AMrXdXvcrb1yXyKQstdgCOTQ2kWphc7NGx6qV/7nXEeVNJDqHv61ZPIpEoDP2HEWhqH3LH3SIF3QYA== X-Received: by 2002:a05:600c:5022:b0:3c6:e61e:ae8c with SMTP id n34-20020a05600c502200b003c6e61eae8cmr49181193wmr.28.1673031323645; Fri, 06 Jan 2023 10:55:23 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Jan 2023 10:55:23 -0800 (PST) From: Attila Lendvai Date: Fri, 6 Jan 2023 19:46:56 +0100 Message-Id: <20230106184654.28037-2-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230106184654.28037-1-attila@lendvai.name> References: <20230106184654.28037-1-attila@lendvai.name> 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This is needed when dealing with golang packages, as per: https://golang.org/ref/mod#vcs-find A page may return 404, but at the same time also contain the sought after `go-import` meta tag. An example for such a project/page is: https://www.gonum.org/v1/gonum?go-get=1 It's not enough to just handle the thrown exception, because we need to be able to get hold of the fetched content, too. * guix/http-client.scm (http-fetch): Add #:accept-all-response-codes? keyword argument defaulting to #f, and implement the logic. --- guix/http-client.scm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 2d48a882e1..341dd7414a 100644 --- a/guix/http-client.scm +++ b/guix/http-client.scm @@ -82,7 +82,8 @@ (define* (http-fetch uri #:key port (text? #f) (buffered? #t) (verify-certificate? #t) (headers '((user-agent . "GNU Guile"))) (log-port (current-error-port)) - timeout) + timeout + (accept-all-response-codes? #f)) "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 @@ -99,7 +100,9 @@ (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." +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 parsed-initial-uri (if (string? uri) (string->uri uri) uri)) @@ -150,7 +153,9 @@ (define (open-connection* uri) current-port) (open-connection* new-uri))))) (else - (raise (condition (&http-get-error + (if accept-all-response-codes? + (values data (response-content-length resp)) + (raise (condition (&http-get-error (uri current-uri) (code code) (reason (response-reason-phrase resp)) @@ -161,7 +166,7 @@ (define (open-connection* uri) #f (G_ "~a: HTTP download failed: ~a (~s)") (uri->string current-uri) code - (response-reason-phrase resp)))))))))))) + (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