diff --git a/503.php b/503.php index 21d3cf2..b47b963 100644 --- a/503.php +++ b/503.php @@ -1,5 +1,5 @@ @@ -138,15 +138,14 @@ http_response_code(404);
🔍
-
404
+
503

-

Seite nicht gefunden

+

Dienst nicht verfügbar

- Die Seite, die du suchst, existiert nicht (mehr)
- oder wurde vielleicht verschoben. + Die Seite die du öffnen willst ist gerade nicht verfügbar

diff --git a/includes/lib/server_status.php b/includes/lib/server_status.php index 218c33c..cecfb6b 100644 --- a/includes/lib/server_status.php +++ b/includes/lib/server_status.php @@ -124,7 +124,7 @@ function is_reachable_http_code(?int $code): bool /** * Perform a lightweight HTTP request (HEAD/GET) without following redirects. - * @return array{ok:bool, code:int|null, ms:int|null, error:string|null} + * @return array{ok:bool, code:int|null, ms:int|null, error:string|null, headers?:array} */ function check_http_request(string $url, string $method, float $timeoutSeconds = 1.6, ?string $extraHeaders = null): array { @@ -190,13 +190,18 @@ function check_http_request(string $url, string $method, float $timeoutSeconds = $error = 'Unbekannter Fehler'; } - return ['ok' => $ok, 'code' => $code, 'ms' => $ms, 'error' => $error]; + $res = ['ok' => $ok, 'code' => $code, 'ms' => $ms, 'error' => $error]; + if (isset($http_response_header) && is_array($http_response_header)) { + $res['headers'] = $http_response_header; + } + + return $res; } /** * HTTP check (no redirects). * - Tries HEAD first. - * - If result is a redirect, probes the Location once (still without following further redirects). + * - If result is a redirect, probes the Location once, because we don't follow redirects automatically. * - If HEAD fails, tries a minimal GET with Range. * @return array{ok:bool, code:int|null, ms:int|null, error:string|null} */ @@ -207,8 +212,8 @@ function check_http_head(string $url, float $timeoutSeconds = 1.6): array // If we got a redirect, probe the Location target once, because we don't follow redirects automatically. if ($head['code'] !== null && $head['code'] >= 300 && $head['code'] < 400) { $loc = null; - if (isset($http_response_header) && is_array($http_response_header)) { - foreach ($http_response_header as $h) { + if (!empty($head['headers']) && is_array($head['headers'])) { + foreach ($head['headers'] as $h) { if (stripos((string)$h, 'Location:') === 0) { $loc = trim(substr((string)$h, strlen('Location:'))); break; @@ -232,12 +237,14 @@ function check_http_head(string $url, float $timeoutSeconds = 1.6): array $probe = check_http_request($loc, 'GET', $timeoutSeconds, "Range: bytes=0-0\r\n"); } - // If the target is clearly reachable/unreachable, use that. if ($probe['code'] !== null && ($probe['code'] < 300 || $probe['code'] >= 400)) { - return $probe; + // return the probe result (drop headers) + if (!$probe['ok'] && empty($probe['error'])) { + $probe['error'] = 'HTTP ' . (string)$probe['code']; + } + return ['ok' => (bool)$probe['ok'], 'code' => $probe['code'], 'ms' => $probe['ms'], 'error' => $probe['error']]; } - // Otherwise keep the redirect info, but don't mark it UP. return ['ok' => false, 'code' => $head['code'], 'ms' => $head['ms'], 'error' => 'Redirect']; } @@ -245,7 +252,7 @@ function check_http_head(string $url, float $timeoutSeconds = 1.6): array } if ($head['ok']) { - return $head; + return ['ok' => true, 'code' => $head['code'], 'ms' => $head['ms'], 'error' => null]; } // If HEAD is not supported/misconfigured, a GET with Range is a cheap reachability check. @@ -253,11 +260,11 @@ function check_http_head(string $url, float $timeoutSeconds = 1.6): array // prefer the GET result if it produced a code (more reliable) if ($get['code'] !== null) { - return $get; + return ['ok' => $get['ok'], 'code' => $get['code'], 'ms' => $get['ms'], 'error' => $get['error']]; } // otherwise fall back to the HEAD info - return $head; + return ['ok' => false, 'code' => $head['code'], 'ms' => $head['ms'], 'error' => $head['error']]; } function build_server_status(array $targets): array