diff options
author | Karol Kosek <krkk@serenityos.org> | 2021-10-16 20:17:18 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-24 23:54:26 +0200 |
commit | a7e7cb0e7032cc6e0bc7a12aee3e9bffa715c14c (patch) | |
tree | 586162bd558b2fa11c3a0584d863a2e6ee12bdd1 /Userland/Libraries | |
parent | 71f663b2056e9b0328783cb57b5db5baa5a317dc (diff) | |
download | serenity-a7e7cb0e7032cc6e0bc7a12aee3e9bffa715c14c.zip |
LibHTTP: Store Content-Length value in the HTTP Job class
This way we can save some calculations, but more importantly this will
also be needed in next commits. :P
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibHTTP/Job.cpp | 19 | ||||
-rw-r--r-- | Userland/Libraries/LibHTTP/Job.h | 1 |
2 files changed, 8 insertions, 12 deletions
diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index aaed0d864a..8d7f2d1d42 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -221,6 +221,10 @@ void Job::on_socket_connected() // Assume that any content-encoding means that we can't decode it as a stream :( dbgln_if(JOB_DEBUG, "Content-Encoding {} detected, cannot stream output :(", value); m_can_stream_response = false; + } else if (name.equals_ignoring_case("Content-Length")) { + auto length = value.to_uint(); + if (length.has_value()) + m_content_length = length.value(); } dbgln_if(JOB_DEBUG, "Job: [{}] = '{}'", name, value); return; @@ -341,19 +345,10 @@ void Job::on_socket_connected() m_current_chunk_remaining_size = size; } - auto content_length_header = m_headers.get("Content-Length"); - Optional<u32> content_length {}; - - if (content_length_header.has_value()) { - auto length = content_length_header.value().to_uint(); - if (length.has_value()) - content_length = length.value(); - } - - deferred_invoke([this, content_length] { did_progress(content_length, m_received_size); }); + deferred_invoke([this] { did_progress(m_content_length, m_received_size); }); - if (content_length.has_value()) { - auto length = content_length.value(); + if (m_content_length.has_value()) { + auto length = m_content_length.value(); if (m_received_size >= length) { m_received_size = length; finish_up(); diff --git a/Userland/Libraries/LibHTTP/Job.h b/Userland/Libraries/LibHTTP/Job.h index 7eb85154df..cbb1b640b3 100644 --- a/Userland/Libraries/LibHTTP/Job.h +++ b/Userland/Libraries/LibHTTP/Job.h @@ -60,6 +60,7 @@ protected: size_t m_buffered_size { 0 }; size_t m_received_size { 0 }; bool m_sent_data { 0 }; + Optional<u32> m_content_length; Optional<ssize_t> m_current_chunk_remaining_size; Optional<size_t> m_current_chunk_total_size; bool m_can_stream_response { true }; |