LibRequests: Add hooks to handle RequestServer death

This commit is contained in:
Timothy Flynn 2025-08-09 13:07:09 -04:00 committed by Andreas Kling
commit 6f4be4791a
Notes: github-actions[bot] 2025-08-10 09:04:18 +00:00
3 changed files with 11 additions and 2 deletions

View file

@ -20,6 +20,7 @@ enum class NetworkError {
SSLVerificationFailed,
MalformedUrl,
InvalidContentEncoding,
RequestServerDied,
Unknown,
};
@ -44,6 +45,8 @@ constexpr StringView network_error_to_string(NetworkError network_error)
return "The URL is not formatted properly"sv;
case NetworkError::InvalidContentEncoding:
return "Response could not be decoded with its Content-Encoding"sv;
case NetworkError::RequestServerDied:
return "RequestServer is currently unavailable"sv;
case NetworkError::Unknown:
return "An unexpected network error occurred"sv;
}

View file

@ -19,8 +19,12 @@ RequestClient::~RequestClient() = default;
void RequestClient::die()
{
// FIXME: Gracefully handle this, or relaunch and reconnect to RequestServer.
warnln("\033[31;1m {} Lost connection to RequestServer\033[0m", Core::System::getpid());
for (auto& [id, request] : m_requests) {
if (request)
request->did_finish({}, {}, {}, NetworkError::RequestServerDied);
}
m_requests.clear();
}
void RequestClient::ensure_connection(URL::URL const& url, ::RequestServer::CacheLevel cache_level)

View file

@ -39,6 +39,8 @@ public:
bool stop_request(Badge<Request>, Request&);
bool set_certificate(Badge<Request>, Request&, ByteString, ByteString);
Function<void()> on_request_server_died;
private:
virtual void die() override;