mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-11 17:00:37 +00:00
CHttpJob: Block until we can actually read during State::InBody.
Also move to State::Finished once we've received >= Content-Length.
This commit is contained in:
parent
6d5633904f
commit
dc8333067f
Notes:
sideshowbarker
2024-07-19 13:30:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/dc8333067f0
1 changed files with 9 additions and 0 deletions
|
@ -78,6 +78,9 @@ void CHttpJob::on_socket_connected()
|
|||
continue;
|
||||
}
|
||||
ASSERT(m_state == State::InBody);
|
||||
while (!m_socket->can_read())
|
||||
usleep(1);
|
||||
ASSERT(m_socket->can_read());
|
||||
auto payload = m_socket->receive(PAGE_SIZE);
|
||||
if (!payload) {
|
||||
if (m_socket->eof()) {
|
||||
|
@ -87,6 +90,12 @@ void CHttpJob::on_socket_connected()
|
|||
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
|
||||
}
|
||||
buffer.append(payload.pointer(), payload.size());
|
||||
|
||||
bool ok;
|
||||
if (buffer.size() >= m_headers.get("Content-Length").to_int(ok) && ok) {
|
||||
m_state = State::Finished;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto response = CHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
|
||||
|
|
Loading…
Reference in a new issue