mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +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
1 changed files with 9 additions and 0 deletions
|
@ -78,6 +78,9 @@ void CHttpJob::on_socket_connected()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ASSERT(m_state == State::InBody);
|
ASSERT(m_state == State::InBody);
|
||||||
|
while (!m_socket->can_read())
|
||||||
|
usleep(1);
|
||||||
|
ASSERT(m_socket->can_read());
|
||||||
auto payload = m_socket->receive(PAGE_SIZE);
|
auto payload = m_socket->receive(PAGE_SIZE);
|
||||||
if (!payload) {
|
if (!payload) {
|
||||||
if (m_socket->eof()) {
|
if (m_socket->eof()) {
|
||||||
|
@ -87,6 +90,12 @@ void CHttpJob::on_socket_connected()
|
||||||
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
|
return deferred_invoke([this](auto&) { did_fail(CNetworkJob::Error::ProtocolFailed); });
|
||||||
}
|
}
|
||||||
buffer.append(payload.pointer(), payload.size());
|
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()));
|
auto response = CHttpResponse::create(m_code, move(m_headers), ByteBuffer::copy(buffer.data(), buffer.size()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue