mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:47:34 +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:
parent
d9ece296f0
commit
1678aaa555
11 changed files with 20 additions and 10 deletions
|
@ -99,7 +99,7 @@ void ClientConnection::did_finish_download(Badge<Download>, Download& download,
|
|||
IPC::Dictionary response_headers;
|
||||
for (auto& it : download.response_headers())
|
||||
response_headers.add(it.key, it.value);
|
||||
post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.total_size().value(), buffer ? buffer->shbuf_id() : -1, response_headers));
|
||||
post_message(Messages::ProtocolClient::DownloadFinished(download.id(), success, download.status_code(), download.total_size().value(), buffer ? buffer->shbuf_id() : -1, response_headers));
|
||||
|
||||
m_downloads.remove(download.id());
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
i32 id() const { return m_id; }
|
||||
URL url() const { return m_url; }
|
||||
|
||||
Optional<u32> status_code() const { return m_status_code; }
|
||||
Optional<u32> total_size() const { return m_total_size; }
|
||||
size_t downloaded_size() const { return m_downloaded_size; }
|
||||
const ByteBuffer& payload() const { return m_payload; }
|
||||
|
@ -54,6 +55,7 @@ protected:
|
|||
|
||||
void did_finish(bool success);
|
||||
void did_progress(Optional<u32> total_size, u32 downloaded_size);
|
||||
void set_status_code(u32 status_code) { m_status_code = status_code; }
|
||||
void set_payload(const ByteBuffer&);
|
||||
void set_response_headers(const HashMap<String, String, CaseInsensitiveStringTraits>&);
|
||||
|
||||
|
@ -61,6 +63,7 @@ private:
|
|||
ClientConnection& m_client;
|
||||
i32 m_id { 0 };
|
||||
URL m_url;
|
||||
Optional<u32> m_status_code;
|
||||
Optional<u32> m_total_size {};
|
||||
size_t m_downloaded_size { 0 };
|
||||
ByteBuffer m_payload;
|
||||
|
|
|
@ -36,6 +36,7 @@ HttpDownload::HttpDownload(ClientConnection& client, NonnullRefPtr<HTTP::HttpJob
|
|||
{
|
||||
m_job->on_finish = [this](bool success) {
|
||||
if (auto* response = m_job->response()) {
|
||||
set_status_code(response->code());
|
||||
set_payload(response->payload());
|
||||
set_response_headers(response->headers());
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ HttpsDownload::HttpsDownload(ClientConnection& client, NonnullRefPtr<HTTP::Https
|
|||
{
|
||||
m_job->on_finish = [this](bool success) {
|
||||
if (auto* response = m_job->response()) {
|
||||
set_status_code(response->code());
|
||||
set_payload(response->payload());
|
||||
set_response_headers(response->headers());
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@ endpoint ProtocolClient = 13
|
|||
{
|
||||
// Download notifications
|
||||
DownloadProgress(i32 download_id, Optional<u32> total_size, u32 downloaded_size) =|
|
||||
DownloadFinished(i32 download_id, bool success, u32 total_size, i32 shbuf_id, IPC::Dictionary response_headers) =|
|
||||
DownloadFinished(i32 download_id, bool success, Optional<u32> status_code, u32 total_size, i32 shbuf_id, IPC::Dictionary response_headers) =|
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue