summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRutherther <rutherther@ditigal.xyz>2025-12-29 11:54:21 +0100
committerRutherther <rutherther@ditigal.xyz>2026-01-14 09:16:50 +0100
commit84a018b3569a26fbb99d0c71fdbd2addb5686467 (patch)
tree0223bc493446ee335c5fd907f3bfb84c15caf13e
parent0ac92150b1e4de3486b453fc10debc082a1a5f1f (diff)
installer: network: Check response code to assess substitute availability.
This is to accomodate following situation: - The proxy is up - The substitute server is down When that happens, 5xx is returned from the proxy, typically either Bad Gateway or Gateway Timeout. This implies the substitute server is down. Still, for checking if the user is online, we do not check the response code. If there is a response, even 4xx, 5xx, it still means the user is online. * gnu/installer/newt/network.scm (url-alive?): Add optional argument to to check the response code. (common-urls-alive?): Add the same argument, passing it to url-alive? (check-substitute-availability): Assume offline when non-successful http code returned. Follow up of 9ea2174ba8f05445227c952e0faa17d9f65ddb8f. Change-Id: I52ae8a49407009dd76ad5da3925355770bc25d0c Change-Id: I99a77cb7332198bae84f28a00a6cc0409d5bf3b9 Signed-off-by: Rutherther <rutherther@ditigal.xyz> Merges: #5217
-rw-r--r--gnu/installer/newt/network.scm24
1 files changed, 16 insertions, 8 deletions
diff --git a/gnu/installer/newt/network.scm b/gnu/installer/newt/network.scm
index c78a7c54612..08e22b8e26c 100644
--- a/gnu/installer/newt/network.scm
+++ b/gnu/installer/newt/network.scm
@@ -27,6 +27,7 @@
#:use-module (guix i18n)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-11)
+ #:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
#:use-module (ice-9 match)
@@ -112,20 +113,24 @@ network devices were found. Do you want to continue anyway?"))
full-value
(+ value 1)))))))
-(define (url-alive? url)
+(define* (url-alive? url #:key (ensure-ok-status? #f))
(false-if-exception
- (begin
- (http-request url)
- #t)))
+ (let ((response (http-request url)))
+ (or (not ensure-ok-status?)
+ (= (response-code response)
+ 200)))))
-(define (common-urls-alive? urls)
+(define* (common-urls-alive? urls #:key (ensure-ok-status? #f))
+ "Return #t if at least some of the given URLS are alive,
+meaning that they do respond to a HTTP request. If ENSURE-OK-STATUS? is
+#t, return #t only if the code is 200."
(dynamic-wind
(lambda ()
(sigaction SIGALRM
(lambda _ #f))
(alarm 3))
(lambda ()
- (any url-alive?
+ (any (cut url-alive? <> #:ensure-ok-status? ensure-ok-status?)
urls))
(lambda ()
(alarm 0))))
@@ -140,7 +145,9 @@ FULL-VALUE tentatives, spaced by 1 second."
"https://bordeaux.guix.gnu.org"
"https://ci.guix.gnu.org"
"https://guix.gnu.org"
- "https://gnu.org")))
+ "https://gnu.org")
+ ;; Any HTTP response means the users is online.
+ #:ensure-ok-status? #f))
(file-exists? "/tmp/installer-assume-online")))
(let* ((full-value 5))
@@ -173,7 +180,8 @@ Do you want to continue anyway?"))
(common-urls-alive?
(list
"https://bordeaux.guix.gnu.org/nix-cache-info"
- "https://ci.guix.gnu.org/nix-cache-info"))))
+ "https://ci.guix.gnu.org/nix-cache-info")
+ #:ensure-ok-status? #t)))
(let* ((full-value 5))
(run-scale-page