shouldDispatch()) { return null; } if (! $this->isServerAvailable()) { return null; } try { $response = Http::timeout(5) ->retry(1, 200) ->post($this->getUrl('/render'), $page) ->throw() ->json(); } catch (Exception $e) { if ($e instanceof StrayRequestException) { throw $e; } $this->serverAvailable = false; return null; } if (is_null($response)) { return null; } $body = $response['body'] ?? ''; $head = $response['head'] ?? []; if (empty($body) && empty($head)) { return null; } return new Response( implode("\n", $head), $body ); } public function isHealthy(): bool { return $this->isServerAvailable(); } private function isServerAvailable(): bool { if ($this->checked) { return $this->serverAvailable; } $this->checked = true; try { $this->serverAvailable = Http::timeout(1) ->get($this->getUrl('/health')) ->successful(); } catch (Exception $e) { if ($e instanceof StrayRequestException) { throw $e; } $this->serverAvailable = false; } return $this->serverAvailable; } }