From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UBRnDGXfUmIUVwEAgWs5BA (envelope-from ) for ; Sun, 10 Apr 2022 15:45:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id sNOVCWXfUmL/NgEA9RJhRA (envelope-from ) for ; Sun, 10 Apr 2022 15:45:09 +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 AB1C9126A6 for ; Sun, 10 Apr 2022 15:45:08 +0200 (CEST) Received: from localhost ([::1]:59666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ndXsJ-00040Y-Ug for larch@yhetil.org; Sun, 10 Apr 2022 09:45:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ndXsE-00040A-GA for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:45871) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ndXsE-0004Oa-7X for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ndXsE-0000ze-1u for guix-patches@gnu.org; Sun, 10 Apr 2022 09:45:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54836] [PATCH v2 1/3] http-client: Added accept-all-response-codes? argument. 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: Sun, 10 Apr 2022 13:45:01 +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.16495982923765 (code B ref 54836); Sun, 10 Apr 2022 13:45:01 +0000 Received: (at 54836) by debbugs.gnu.org; 10 Apr 2022 13:44:52 +0000 Received: from localhost ([127.0.0.1]:39762 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs4-0000ye-45 for submit@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:52 -0400 Received: from mail-ed1-f54.google.com ([209.85.208.54]:40481) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ndXs1-0000yL-Sr for 54836@debbugs.gnu.org; Sun, 10 Apr 2022 09:44:50 -0400 Received: by mail-ed1-f54.google.com with SMTP id v4so1720411edl.7 for <54836@debbugs.gnu.org>; Sun, 10 Apr 2022 06:44:49 -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=++3ok8LxQxAfqdef0Oab922kDhcqy0nEv2t3ab3GQ7M=; b=df/eAmBjq/hvxwW4yIHjwMvknW8A++InQJEwxvR1Y722E6XFbaS41yqcMLq/NXfbni U/2heogZc9R+Kq8AbqmAY1NPkUWkh1SFhJ35ygX/InXljBtqSaZSdkjdW8yeGOpfKKSQ X3GKbnbcmnQVL0ElcmTxX5kI/KHSCQmlaRuSAce3EvKPr01WemwiGcCNSkXKqwZiOkyk UNWWL+cFuGgr8AXwltUDUrAs2ugBzntwg4OO0OeIgM2h8+pnmzKbtyQfaByWyewJalRD RQwHkP6It7y0BjEMc87UQ+KqbD918PsvIqDFFbZ3qpAtMze/J8Shz92TVB6gaRDOgIWN XIDw== 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=++3ok8LxQxAfqdef0Oab922kDhcqy0nEv2t3ab3GQ7M=; b=pM6nI1qSSJltugXMQ6n+GuATfBF7yDbV2nPbdF09RkBtekY1y+Nqbn3oh2gVCwoJ/R re9xeVRq1JUUF4mzTvFmMrpqvs7Swy0AqLyWVxuz4zch16D+drBdmAbd7cKb9EoYpYBR gzOQSWCoj+sqae8wfogrsOWlL07d8e1WZ8qcyQjOGxGvR0ar8wHbxq3VqWrKE47xqAqe qAbGBkVWYQnZyiqZLfFP1JMIIUW+NBc10qv4eGPYj9lpkn37NK7OaDE/2SQOP7igVasc BrVON1E8ndWvGiq3EwfW60yPhDM4Ts3dzFtcF1NnIgUz8IBBb2KYJmjtv3/FqmOArz/i 6XAw== X-Gm-Message-State: AOAM533Bi08kT1UUf0Eon4bVQWE9FNtANweyOH5vsJGIgMV5ABe0GA+N ynDZk+r9TPwyUQw0LFABHjnFsVlsDag= X-Google-Smtp-Source: ABdhPJwAuLJ3qNC+BxCUXXzFWU34Ttkhy5wcwP4xrhUHjaWikyj92i1O3diaJll1zqZz3/CNy8ydig== X-Received: by 2002:aa7:c612:0:b0:41d:7ad7:4a4d with SMTP id h18-20020aa7c612000000b0041d7ad74a4dmr820442edq.125.1649598283998; Sun, 10 Apr 2022 06:44:43 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Apr 2022 06:44:43 -0700 (PDT) From: Attila Lendvai Date: Sun, 10 Apr 2022 15:41:13 +0200 Message-Id: <20220410134114.371-1-attila@lendvai.name> X-Mailer: git-send-email 2.34.0 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=1649598308; 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=++3ok8LxQxAfqdef0Oab922kDhcqy0nEv2t3ab3GQ7M=; b=EyUkdqKIP3vb9HCseoVrCNmbkeMQzFedJ1ArVPN2F7TYYu7JuYu/mgiKBYtepNP2vA75ww 1XO6Om570n/AGX9F4ZCGQstSrZhlXoeUOW9FTKhZLHHiJPVrcugNEPmROSZzFJI/U0kH+K Lj9nWqR1Khk8ZQyG35tDoNUSMQmsAbxbrHHnYz8I+H4jzfm13oPLopcv3YWt7rp5kNvvKi /8GlMEB+Xgwtf4tiKhyI1bI/BS/oY2q4s1VadnFyNE+men0XGIpjAQTOVRMhXCqsAMe5X3 f1ypknfTh+4NJJx0MM4pd2u6aqzZsfWylXfwdirNdNeA/qlK2gwXcW38RwZNZA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649598308; a=rsa-sha256; cv=none; b=URfIfH0zlqFXOyEoDgD8dUP61i96Wrz6nG06BxnuFM6sf6jS5+dhRjfac0sotjBtr/Xfc/ QU47m0D78IrFoaVC1F1h+ty5wCZR0HIasBDrRVgva88EqykTnO42azQvm/mXnyGARating OhT46IiVrjFuU/iG0vrZtCclrcB6ErKP7/lmztRlauew1XQ9L0IxuAZ6shyxdO4NPbYBVu XakG+Mt/4I347/7+fa+QPByJjLlmAvbpIW8ZkKD4Z+TvIsJ3CBHPTyxkfvbW8jppZtyRm5 oi/z3Uoki/1HtfR+QfXjDCnxJ3tnMfAV7H+DpEFOxg6NrJoQHX9uIpQSFls4pw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="df/eAmBj"; 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.43 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b="df/eAmBj"; 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: AB1C9126A6 X-Spam-Score: 2.43 X-Migadu-Scanner: scn1.migadu.com X-TUID: IoLXuO0stEGf 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. --- oops, resending because the first version doesn't apply on master. v2 also contains an initial commit, a feature addition that is needed for my (soon to be sent) improvements to the go importer. guix/http-client.scm | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/guix/http-client.scm b/guix/http-client.scm index 143ed6de31..8a5b3deecd 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 uri* (if (string? uri) (string->uri uri) uri)) @@ -150,18 +153,20 @@ (define uri* verify-certificate? #:timeout timeout))))) (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)))))))))))) + (if accept-all-response-codes? + (values data (response-content-length resp)) + (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))))))))))))) (define-syntax-rule (false-if-networking-error exp) "Return #f if EXP triggers a network related exception as can occur when -- 2.34.0