1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:37:45 +00:00

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

View file

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