mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 11:20:03 +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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user