mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 00:50:22 +00:00
LibWeb: Fix handling of SSEs split across chunks
This commit is contained in:
parent
f2034270f1
commit
347928b950
Notes:
github-actions[bot]
2024-08-17 16:55:23 +00:00
Author: https://github.com/vpzomtrrfrt Commit: https://github.com/LadybirdBrowser/ladybird/commit/347928b9508 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/952 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 15 additions and 2 deletions
|
@ -130,9 +130,22 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<EventSource>> EventSource::construct_impl(J
|
|||
else {
|
||||
event_source->announce_the_connection();
|
||||
|
||||
auto process_body_chunk = JS::create_heap_function(realm.heap(), [event_source](ByteBuffer body) {
|
||||
event_source->interpret_response(body);
|
||||
auto process_body_chunk = JS::create_heap_function(realm.heap(), [event_source, pending_data = ByteBuffer()](ByteBuffer body) mutable {
|
||||
if (pending_data.is_empty())
|
||||
pending_data = move(body);
|
||||
else
|
||||
pending_data.append(body);
|
||||
|
||||
auto last_line_break = AK::StringUtils::find_any_of(pending_data, "\r\n"sv, AK::StringUtils::SearchDirection::Backward);
|
||||
if (!last_line_break.has_value())
|
||||
return;
|
||||
|
||||
auto end_index = *last_line_break + 1;
|
||||
event_source->interpret_response({ pending_data.bytes().slice(0, end_index) });
|
||||
|
||||
pending_data = MUST(pending_data.slice(end_index, pending_data.size() - end_index));
|
||||
});
|
||||
|
||||
auto process_end_of_body = JS::create_heap_function(realm.heap(), []() {
|
||||
// This case is handled by `process_event_source_end_of_body` above.
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue