summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-19 02:31:40 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-09-19 21:10:23 +0430
commitc5d7eb86189e0fbd9f6a9da1afe29b6a9ab533a4 (patch)
treeb51da644ae2d2782dddc6afcb4fd9e5f5c0a0db8 /Userland
parent6819193671b5a2a28153f846bc65d90c6ee67a4c (diff)
downloadserenity-c5d7eb86189e0fbd9f6a9da1afe29b6a9ab533a4.zip
LibHTTP: Exit the read loop early when there cannot be any further data
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibHTTP/Job.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp
index 5324267522..5c75997db8 100644
--- a/Userland/Libraries/LibHTTP/Job.cpp
+++ b/Userland/Libraries/LibHTTP/Job.cpp
@@ -175,6 +175,14 @@ void Job::on_socket_connected()
on_headers_received(m_headers, m_code > 0 ? m_code : Optional<u32> {});
m_state = State::InBody;
}
+
+ // We've reached the end of the headers, there's a possibility that the server
+ // responds with nothing (content-length = 0 with normal encoding); if that's the case,
+ // quit early as we won't be reading anything anyway.
+ if (auto result = m_headers.get("Content-Length"sv).value_or(""sv).to_uint(); result.has_value()) {
+ if (result.value() == 0 && !m_headers.get("Transfer-Encoding"sv).value_or(""sv).view().trim_whitespace().equals_ignoring_case("chunked"sv))
+ return finish_up();
+ }
return;
}
auto parts = line.split_view(':');