LibProtocol+Userland: Support unbuffered protocol requests

LibWeb will need to use unbuffered requests to support server-sent
events. Connection for such events remain open and the remote end sends
data as HTTP bodies at its leisure. The browser needs to be able to
handle this data as it arrives, as the request essentially never
finishes.

To support this, this make Protocol::Request operate in one of two
modes: buffered or unbuffered. The existing mechanism for setting up a
buffered request was a bit awkward; you had to set specific callbacks,
but be sure not to set some others, and then set a flag. The new
mechanism is to set the mode and the callbacks that the mode needs in
one API.
This commit is contained in:
Timothy Flynn 2024-05-24 11:37:02 -04:00 committed by Andreas Kling
parent 086ddd481d
commit 168d28c15f
Notes: sideshowbarker 2024-07-17 03:16:02 +09:00
14 changed files with 189 additions and 129 deletions

View file

@ -13,6 +13,7 @@
#include <LibCore/EventReceiver.h>
#include <LibCore/Proxy.h>
#include <LibJS/SafeFunction.h>
#include <LibProtocol/Request.h>
#include <LibURL/URL.h>
#include <LibWeb/Loader/Resource.h>
#include <LibWeb/Page/Page.h>
@ -32,13 +33,16 @@ public:
ByteString key;
};
virtual void set_should_buffer_all_input(bool) = 0;
// Configure the request such that the entirety of the response data is buffered. The callback receives that data and
// the response headers all at once. Using this method is mutually exclusive with `set_unbuffered_data_received_callback`.
virtual void set_buffered_request_finished_callback(Protocol::Request::BufferedRequestFinished) = 0;
// Configure the request such that the response data is provided unbuffered as it is received. Using this method is
// mutually exclusive with `set_buffered_request_finished_callback`.
virtual void set_unbuffered_request_callbacks(Protocol::Request::HeadersReceived, Protocol::Request::DataReceived, Protocol::Request::RequestFinished) = 0;
virtual bool stop() = 0;
virtual void stream_into(Stream&) = 0;
Function<void(bool success, u64 total_size, HashMap<ByteString, ByteString, CaseInsensitiveStringTraits> const& response_headers, Optional<u32> response_code, ReadonlyBytes payload)> on_buffered_request_finish;
Function<void(bool success, u64 total_size)> on_finish;
Function<void(Optional<u64> total_size, u64 downloaded_size)> on_progress;
Function<CertificateAndKey()> on_certificate_requested;