1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 17:15:08 +00:00

ProtocolServer+LibProtocol: Propagate HTTP status codes to clients

Clients now receive HTTP status codes like 200, 404, etc.
Note that a 404 with content is still considered a "successful"
download from ProtocolServer's perspective. It's up to the client
to interpret the status code.

I'm not sure if this is the best API, but it'll work for now.
This commit is contained in:
Andreas Kling 2020-06-13 22:19:34 +02:00
parent d9ece296f0
commit 1678aaa555
11 changed files with 20 additions and 10 deletions

View file

@ -163,7 +163,7 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&, const
error_callback("Failed to initiate load");
return;
}
download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, const ByteBuffer& payload, auto, auto& response_headers) {
download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, const ByteBuffer& payload, auto, auto& response_headers, auto status_code) {
--m_pending_loads;
if (on_load_counter_change)
on_load_counter_change();
@ -172,6 +172,11 @@ void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&, const
error_callback("HTTP load failed");
return;
}
if (status_code.has_value() && status_code.value() == 404) {
if (error_callback)
error_callback("HTTP not found (four-oh-four!)");
return;
}
success_callback(ByteBuffer::copy(payload.data(), payload.size()), response_headers);
};
++m_pending_loads;