mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +00:00
ProtocolServer: Pass HTTP response headers to the client
We now store the response headers in a download object on the protocol server side and pass it to the client when finishing up a download. Response headers are passed as an IPC::Dictionary. :^)
This commit is contained in:
parent
a83d74b38c
commit
eb6e35a1be
18 changed files with 49 additions and 30 deletions
|
@ -68,7 +68,7 @@ void Client::handle(const Messages::ProtocolClient::DownloadFinished& message)
|
|||
{
|
||||
RefPtr<Download> download;
|
||||
if ((download = m_downloads.get(message.download_id()).value_or(nullptr))) {
|
||||
download->did_finish({}, message.success(), message.total_size(), message.shbuf_id());
|
||||
download->did_finish({}, message.success(), message.total_size(), message.shbuf_id(), message.response_headers());
|
||||
}
|
||||
send_sync<Messages::ProtocolServer::DisownSharedBuffer>(message.shbuf_id());
|
||||
m_downloads.remove(message.download_id());
|
||||
|
|
|
@ -41,7 +41,7 @@ bool Download::stop()
|
|||
return m_client->stop_download({}, *this);
|
||||
}
|
||||
|
||||
void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id)
|
||||
void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id, const IPC::Dictionary& response_headers)
|
||||
{
|
||||
if (!on_finish)
|
||||
return;
|
||||
|
@ -52,7 +52,8 @@ void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf
|
|||
shared_buffer = SharedBuffer::create_from_shbuf_id(shbuf_id);
|
||||
payload = ByteBuffer::wrap(shared_buffer->data(), total_size);
|
||||
}
|
||||
on_finish(success, payload, move(shared_buffer));
|
||||
|
||||
on_finish(success, payload, move(shared_buffer), response_headers.entries());
|
||||
}
|
||||
|
||||
void Download::did_progress(Badge<Client>, Optional<u32> total_size, u32 downloaded_size)
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include <AK/Function.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
namespace Protocol {
|
||||
|
||||
|
@ -46,10 +47,10 @@ public:
|
|||
int id() const { return m_download_id; }
|
||||
bool stop();
|
||||
|
||||
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage)> on_finish;
|
||||
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String>& response_headers)> on_finish;
|
||||
Function<void(Optional<u32> total_size, u32 downloaded_size)> on_progress;
|
||||
|
||||
void did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id);
|
||||
void did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf_id, const IPC::Dictionary& response_headers);
|
||||
void did_progress(Badge<Client>, Optional<u32> total_size, u32 downloaded_size);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue