From 819598aecf91a81e25aceba5ef512fd57d3252a6 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 2 Nov 2022 12:53:03 -0400 Subject: [PATCH] WebContent: Support sending large responses to the WebDriver client Some endpoints, like /session/{id}/screenshot, will require sending large data to the client. We won't be able to write all of the data in one shot, so loop over the data until we've sent it all (or fail). --- Userland/Services/WebDriver/Client.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Services/WebDriver/Client.cpp b/Userland/Services/WebDriver/Client.cpp index fd6a1e223c..d3c52b0fe7 100644 --- a/Userland/Services/WebDriver/Client.cpp +++ b/Userland/Services/WebDriver/Client.cpp @@ -197,7 +197,12 @@ ErrorOr Client::send_response(StringView content, HTTP::HttpRequest const& auto builder_contents = builder.to_byte_buffer(); TRY(m_socket->write(builder_contents)); - TRY(m_socket->write(content.bytes())); + + while (!content.is_empty()) { + auto bytes_sent = TRY(m_socket->write(content.bytes())); + content = content.substring_view(bytes_sent); + } + log_response(200, request); auto keep_alive = false;