mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
Previously, unbuffered requests were only available as a special mode for EventSource. With this change, they are enabled by default, which means chunks can be read from the stream as soon as they arrive. This unlocks some interesting possibilities, such as starting to parse HTML documents before the entire response has been received (that, in turn, allows us to initiate subresource fetches earlier or begin executing scripts sooner), or start rendering videos before they are fully downloaded. Co-authored-by: Timothy Flynn <trflynn89@pm.me>
56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.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 <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>);
|
|
|
|
virtual void visit_edges(Visitor& visitor) override;
|
|
|
|
void pull_bytes_into_stream(ByteBuffer&&);
|
|
void close_stream();
|
|
|
|
GC::Ref<Infrastructure::FetchParams const> m_fetch_params;
|
|
GC::Ref<Streams::ReadableStream> m_stream;
|
|
GC::Ptr<WebIDL::Promise> m_pending_promise;
|
|
|
|
ByteBuffer m_buffer;
|
|
enum class LifecycleState {
|
|
Receiving,
|
|
CompletePending,
|
|
ReadyToClose,
|
|
Closed,
|
|
};
|
|
LifecycleState m_lifecycle_state { LifecycleState::Receiving };
|
|
bool m_has_unfulfilled_promise { false };
|
|
};
|
|
|
|
}
|