From 0bd9a94bea46bceefbc40b449ea761579a4b37a7 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Mon, 12 Dec 2022 18:30:29 +0100 Subject: [PATCH] LibHTTP: Don't read and drop data if status line can't be read The idea of reading some amount of data presumably was to check if the stream is still operable. However, this permanently breaks the request format, as those 64 bytes are just lost forever. Instead, just let the request fail instantly for now and think about making it retry some time in the future. Since `can_read_line` updates the read buffer beforehand, this should only happen in the rarest of cases anyways. --- Userland/Libraries/LibHTTP/Job.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index e81aba01482..678ce97138c 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -251,16 +251,11 @@ void Job::on_socket_connected() } if (!can_read_line.value()) { - dbgln_if(JOB_DEBUG, "Job {} cannot read line", m_request.url()); - auto maybe_buf = receive(64); - if (maybe_buf.is_error()) { - dbgln_if(JOB_DEBUG, "Job {} cannot read any bytes!", m_request.url()); - return deferred_invoke([this] { did_fail(Core::NetworkJob::Error::TransmissionFailed); }); - } - - dbgln_if(JOB_DEBUG, "{} bytes was read", maybe_buf.value().bytes().size()); - return; + dbgln_if(JOB_DEBUG, "Job {} cannot read a full line", m_request.url()); + // TODO: Should we retry here instead of failing instantly? + return deferred_invoke([this] { did_fail(Core::NetworkJob::Error::TransmissionFailed); }); } + auto maybe_line = read_line(PAGE_SIZE); if (maybe_line.is_error()) { dbgln_if(JOB_DEBUG, "Job {} could not read line: {}", m_request.url(), maybe_line.error());