From: Attila Lendvai <attila@lendvai.name>
To: 54836@debbugs.gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [bug#54836] [PATCH v2 1/3] http-client: Added accept-all-response-codes? argument.
Date: Sun, 10 Apr 2022 15:41:13 +0200 [thread overview]
Message-ID: <20220410134114.371-1-attila@lendvai.name> (raw)
In-Reply-To: <20220410133431.30058-1-attila@lendvai.name>
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
next prev parent reply other threads:[~2022-04-10 13:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-10 13:34 [bug#54836] [PATCH 1/2] http-client: Fix redirection Attila Lendvai
2022-04-10 13:35 ` [bug#54836] [PATCH 2/2] http-client: Factor out open-connection*, rename variables Attila Lendvai
2022-04-10 13:41 ` Attila Lendvai [this message]
2022-04-10 13:41 ` [bug#54836] [PATCH 2/3] http-client: Fix redirection Attila Lendvai
2022-04-11 12:44 ` [bug#54836] [PATCH 1/2] " Ludovic Courtès
2022-04-10 13:41 ` [bug#54836] [PATCH 3/3] http-client: Factor out open-connection*, rename variables Attila Lendvai
2022-04-11 12:45 ` [bug#54836] [PATCH 1/2] http-client: Fix redirection Ludovic Courtès
2022-04-12 7:28 ` Attila Lendvai
2022-04-27 16:37 ` Attila Lendvai
2022-04-27 20:53 ` Ludovic Courtès
2023-01-03 22:29 ` Maxim Cournoyer
2022-04-28 10:22 ` [bug#54836] [PATCH v3] http-client: Factor out open-connection*, rename variables Attila Lendvai
2023-01-06 18:46 ` [bug#54836] [PATCH v4 1/2] " Attila Lendvai
2023-01-06 18:46 ` [bug#54836] [PATCH v4 2/2] http-client: Added accept-all-response-codes? argument Attila Lendvai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220410134114.371-1-attila@lendvai.name \
--to=attila@lendvai.name \
--cc=54836@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.