1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

LibHTTP: Trim the last packet if it exceeded the Content-Length value

Used these commands to test it:

  printf 'HTTP/1.0 200 OK\r\n%s\r\n\r\n%s' 'Content-Length: 4' \
      'well hello friends!' | nc -lN 0.0.0.0 8000
  pro http://0.0.0.0:8000
This commit is contained in:
Karol Kosek 2021-10-16 20:17:25 +02:00 committed by Andreas Kling
parent a7e7cb0e70
commit 89c87ff7b9

View file

@ -316,11 +316,27 @@ void Job::on_socket_connected()
}
}
bool read_everything = false;
if (m_content_length.has_value()) {
auto length = m_content_length.value();
if (m_received_size + payload.size() >= length) {
payload.resize(length - m_buffered_size);
read_everything = true;
}
}
m_received_buffers.append(payload);
m_buffered_size += payload.size();
m_received_size += payload.size();
flush_received_buffers();
deferred_invoke([this] { did_progress(m_content_length, m_received_size); });
if (read_everything) {
finish_up();
return IterationDecision::Break;
}
if (m_current_chunk_remaining_size.has_value()) {
auto size = m_current_chunk_remaining_size.value() - payload.size();
@ -345,16 +361,6 @@ void Job::on_socket_connected()
m_current_chunk_remaining_size = size;
}
deferred_invoke([this] { did_progress(m_content_length, m_received_size); });
if (m_content_length.has_value()) {
auto length = m_content_length.value();
if (m_received_size >= length) {
m_received_size = length;
finish_up();
return IterationDecision::Break;
}
}
return IterationDecision::Continue;
});