summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-22 23:10:05 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-22 23:10:05 +0200
commitdc8333067f060692a8dedad43c45d7c6b171a9f8 (patch)
tree48c8d41ea06dd20004cd791ca6f2cf443614cd81
parent6d5633904f5779a5edab3078851eb19cb1febb53 (diff)
downloadserenity-dc8333067f060692a8dedad43c45d7c6b171a9f8.zip
CHttpJob: Block until we can actually read during State::InBody.
Also move to State::Finished once we've received >= Content-Length.
-rw-r--r--LibCore/CHttpJob.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/LibCore/CHttpJob.cpp b/LibCore/CHttpJob.cpp
index e580fd87c2..5787dbebfc 100644
--- a/LibCore/CHttpJob.cpp
+++ b/LibCore/CHttpJob.cpp
@@ -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()));