mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 03:57:15 +02:00
The in-memory HTTP Fetch cache currently keeps the realm which created each cache entry alive indefinitely. This patch migrates this cache to LibHTTP, to ensure it is completely unaware of any JS objects. Now that we are not interacting with Fetch response objects, we can no longer use Streams infrastructure to pipe the response body into the Fetch response. Fetch also ultimately creates the cache response once the HTTP response headers have arrived. So the LibHTTP cache will hold entries in a pending list until we have received the entire response body. Then it is moved to a completed list and may be used thereafter.
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) 2024-2025, Tim Flynn <trflynn89@ladybird.org>
|
|
* Copyright (c) 2025, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
#include <LibGC/CellAllocator.h>
|
|
#include <LibHTTP/Forward.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::Fetch::Fetching {
|
|
|
|
class FetchedDataReceiver final : public JS::Cell {
|
|
GC_CELL(FetchedDataReceiver, JS::Cell);
|
|
GC_DECLARE_ALLOCATOR(FetchedDataReceiver);
|
|
|
|
public:
|
|
virtual ~FetchedDataReceiver() override;
|
|
|
|
void set_pending_promise(GC::Ref<WebIDL::Promise>);
|
|
|
|
enum class NetworkState {
|
|
Ongoing,
|
|
Complete,
|
|
Error,
|
|
};
|
|
void handle_network_bytes(ReadonlyBytes, NetworkState);
|
|
|
|
private:
|
|
FetchedDataReceiver(GC::Ref<Infrastructure::FetchParams const>, GC::Ref<Streams::ReadableStream>, RefPtr<HTTP::MemoryCache>);
|
|
|
|
virtual void visit_edges(Visitor& visitor) override;
|
|
|
|
void pull_bytes_into_stream();
|
|
void close_stream();
|
|
|
|
bool buffer_is_eof() const { return m_pulled_bytes == m_buffer.size(); }
|
|
ByteBuffer copy_unpulled_bytes();
|
|
|
|
GC::Ref<Infrastructure::FetchParams const> m_fetch_params;
|
|
GC::Ref<Streams::ReadableStream> m_stream;
|
|
GC::Ptr<WebIDL::Promise> m_pending_promise;
|
|
|
|
RefPtr<HTTP::MemoryCache> m_http_cache;
|
|
|
|
ByteBuffer m_buffer;
|
|
size_t m_pulled_bytes { 0 };
|
|
|
|
enum class LifecycleState {
|
|
Receiving,
|
|
CompletePending,
|
|
ReadyToClose,
|
|
Closed,
|
|
};
|
|
LifecycleState m_lifecycle_state { LifecycleState::Receiving };
|
|
bool m_has_unfulfilled_promise { false };
|
|
};
|
|
|
|
}
|