mirror of
https://codeberg.org/guix/guix.git
synced 2026-01-25 12:05:19 -06:00
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 9ea2174ba8.
Change-Id: I52ae8a49407009dd76ad5da3925355770bc25d0c
Change-Id: I99a77cb7332198bae84f28a00a6cc0409d5bf3b9
Signed-off-by: Rutherther <rutherther@ditigal.xyz>
Merges: #5217
This commit is contained in:
parent
0ac92150b1
commit
84a018b356
1 changed files with 16 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue