mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-05 07:39:16 +00:00
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:
parent
086ddd481d
commit
168d28c15f
Notes:
sideshowbarker
2024-07-17 03:16:02 +09:00
Author: https://github.com/trflynn89
Commit: 168d28c15f
Pull-request: https://github.com/SerenityOS/serenity/pull/24452
Issue: https://github.com/SerenityOS/serenity/issues/23847
14 changed files with 189 additions and 129 deletions
|
@ -19,18 +19,6 @@ ErrorOr<NonnullRefPtr<RequestServerRequestAdapter>> RequestServerRequestAdapter:
|
|||
RequestServerRequestAdapter::RequestServerRequestAdapter(NonnullRefPtr<Protocol::Request> request)
|
||||
: m_request(request)
|
||||
{
|
||||
request->on_buffered_request_finish = [weak_this = make_weak_ptr()](auto success, auto total_size, auto const& response_headers, auto response_code, auto payload) {
|
||||
if (auto strong_this = weak_this.strong_ref())
|
||||
if (strong_this->on_buffered_request_finish)
|
||||
strong_this->on_buffered_request_finish(success, total_size, response_headers, response_code, move(payload));
|
||||
};
|
||||
|
||||
request->on_finish = [weak_this = make_weak_ptr()](bool success, u64 total_size) {
|
||||
if (auto strong_this = weak_this.strong_ref())
|
||||
if (strong_this->on_finish)
|
||||
strong_this->on_finish(success, total_size);
|
||||
};
|
||||
|
||||
request->on_progress = [weak_this = make_weak_ptr()](Optional<u64> total_size, u64 downloaded_size) {
|
||||
if (auto strong_this = weak_this.strong_ref())
|
||||
if (strong_this->on_progress)
|
||||
|
@ -54,9 +42,14 @@ RequestServerRequestAdapter::RequestServerRequestAdapter(NonnullRefPtr<Protocol:
|
|||
|
||||
RequestServerRequestAdapter::~RequestServerRequestAdapter() = default;
|
||||
|
||||
void RequestServerRequestAdapter::set_should_buffer_all_input(bool should_buffer_all_input)
|
||||
void RequestServerRequestAdapter::set_buffered_request_finished_callback(Protocol::Request::BufferedRequestFinished on_buffered_request_finished)
|
||||
{
|
||||
m_request->set_should_buffer_all_input(should_buffer_all_input);
|
||||
m_request->set_buffered_request_finished_callback(move(on_buffered_request_finished));
|
||||
}
|
||||
|
||||
void RequestServerRequestAdapter::set_unbuffered_request_callbacks(Protocol::Request::HeadersReceived on_headers_received, Protocol::Request::DataReceived on_data_received, Protocol::Request::RequestFinished on_finished)
|
||||
{
|
||||
m_request->set_unbuffered_request_callbacks(move(on_headers_received), move(on_data_received), move(on_finished));
|
||||
}
|
||||
|
||||
bool RequestServerRequestAdapter::stop()
|
||||
|
@ -64,11 +57,6 @@ bool RequestServerRequestAdapter::stop()
|
|||
return m_request->stop();
|
||||
}
|
||||
|
||||
void RequestServerRequestAdapter::stream_into(Stream& stream)
|
||||
{
|
||||
m_request->stream_into(stream);
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<RequestServerAdapter>> RequestServerAdapter::try_create(NonnullRefPtr<Protocol::RequestClient> protocol_client)
|
||||
{
|
||||
return try_make_ref_counted<RequestServerAdapter>(move(protocol_client));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue