WebServer: Don't read until EOF

There's no guarantee that the client has closed the socket for
writing. Instead we should just read until the first empty line.

Fixes #7064.
This commit is contained in:
Gunnar Beutner 2021-05-17 20:30:24 +02:00 committed by Andreas Kling
parent f1dc8e12d2
commit 7aca2d181a
Notes: sideshowbarker 2024-07-18 17:55:34 +09:00

View file

@ -40,15 +40,18 @@ void Client::die()
void Client::start()
{
m_socket->on_ready_to_read = [this] {
auto raw_request = m_socket->read_all();
if (raw_request.is_empty()) {
die();
return;
StringBuilder builder;
for (;;) {
auto line = m_socket->read_line();
if (line.is_empty())
break;
builder.append(line);
builder.append("\r\n");
}
dbgln("Got raw request: '{}'", String::copy(raw_request));
handle_request(raw_request.bytes());
auto request = builder.to_byte_buffer();
dbgln("Got raw request: '{}'", String::copy(request));
handle_request(request);
die();
};
}