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

View file

@ -19,8 +19,12 @@ RequestClient::~RequestClient() = default;
void RequestClient::die() void RequestClient::die()
{ {
// FIXME: Gracefully handle this, or relaunch and reconnect to RequestServer. for (auto& [id, request] : m_requests) {
warnln("\033[31;1m {} Lost connection to RequestServer\033[0m", Core::System::getpid()); if (request)
request->did_finish({}, {}, {}, NetworkError::RequestServerDied);
}
m_requests.clear();
} }
void RequestClient::ensure_connection(URL::URL const& url, ::RequestServer::CacheLevel cache_level) 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 stop_request(Badge<Request>, Request&);
bool set_certificate(Badge<Request>, Request&, ByteString, ByteString); bool set_certificate(Badge<Request>, Request&, ByteString, ByteString);
Function<void()> on_request_server_died;
private: private:
virtual void die() override; virtual void die() override;