LibProtocol: Pass response headers in a case insensitive HashMap

HTTP headers are case-insensitive, so just add CaseInsensitiveTraits
to the HashMap and we're good to go! :^)
This commit is contained in:
Andreas Kling 2020-05-10 21:26:53 +02:00
parent aef5d28828
commit 20f50f9133
Notes: sideshowbarker 2024-07-19 06:44:47 +09:00
6 changed files with 16 additions and 10 deletions

View file

@ -59,7 +59,7 @@ DownloadWidget::DownloadWidget(const URL& url)
m_download->on_progress = [this](Optional<u32> total_size, u32 downloaded_size) {
did_progress(total_size.value(), downloaded_size);
};
m_download->on_finish = [this](bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String>& response_headers) {
m_download->on_finish = [this](bool success, auto& payload, auto payload_storage, auto& response_headers) {
did_finish(success, payload, payload_storage, response_headers);
};
@ -156,7 +156,7 @@ void DownloadWidget::did_progress(Optional<u32> total_size, u32 downloaded_size)
}
}
void DownloadWidget::did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String>& response_headers)
void DownloadWidget::did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)
{
(void)payload;
(void)payload_storage;

View file

@ -44,7 +44,7 @@ private:
explicit DownloadWidget(const URL&);
void did_progress(Optional<u32> total_size, u32 downloaded_size);
void did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String>& response_headers);
void did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers);
URL m_url;
String m_destination_path;

View file

@ -53,7 +53,13 @@ void Download::did_finish(Badge<Client>, bool success, u32 total_size, i32 shbuf
payload = ByteBuffer::wrap(shared_buffer->data(), total_size);
}
on_finish(success, payload, move(shared_buffer), response_headers.entries());
// FIXME: It's a bit silly that we copy the response headers here just so we can move them into a HashMap with different traits.
HashMap<String, String, CaseInsensitiveStringTraits> caseless_response_headers;
response_headers.for_each_entry([&](auto& name, auto& value) {
caseless_response_headers.set(name, value);
});
on_finish(success, payload, move(shared_buffer), caseless_response_headers);
}
void Download::did_progress(Badge<Client>, Optional<u32> total_size, u32 downloaded_size)
@ -61,5 +67,4 @@ void Download::did_progress(Badge<Client>, Optional<u32> total_size, u32 downloa
if (on_progress)
on_progress(total_size, downloaded_size);
}
}

View file

@ -30,6 +30,7 @@
#include <AK/ByteBuffer.h>
#include <AK/Function.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/WeakPtr.h>
#include <LibIPC/Forward.h>
@ -47,7 +48,7 @@ public:
int id() const { return m_download_id; }
bool stop();
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String>& response_headers)> on_finish;
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& 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, const IPC::Dictionary& response_headers);

View file

@ -47,7 +47,7 @@ ResourceLoader::ResourceLoader()
{
}
void ResourceLoader::load_sync(const URL& url, Function<void(const ByteBuffer&, const HashMap<String, String>& response_headers)> success_callback, Function<void(const String&)> error_callback)
void ResourceLoader::load_sync(const URL& url, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback)
{
Core::EventLoop loop;
@ -66,7 +66,7 @@ void ResourceLoader::load_sync(const URL& url, Function<void(const ByteBuffer&,
loop.exec();
}
void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&, const HashMap<String, String>& response_headers)> success_callback, Function<void(const String&)> error_callback)
void ResourceLoader::load(const URL& url, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback)
{
if (is_port_blocked(url.port())) {
dbg() << "ResourceLoader::load: Error: blocked port " << url.port() << " for URL: " << url;

View file

@ -41,8 +41,8 @@ class ResourceLoader : public Core::Object {
public:
static ResourceLoader& the();
void load(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
void load_sync(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
void load(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
void load_sync(const URL&, Function<void(const ByteBuffer&, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)> success_callback, Function<void(const String&)> error_callback = nullptr);
Function<void()> on_load_counter_change;