mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 17:17:42 +00:00
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
This commit is contained in:
parent
71f663b205
commit
a7e7cb0e70
2 changed files with 8 additions and 12 deletions
|
@ -221,6 +221,10 @@ void Job::on_socket_connected()
|
||||||
// Assume that any content-encoding means that we can't decode it as a stream :(
|
// 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);
|
dbgln_if(JOB_DEBUG, "Content-Encoding {} detected, cannot stream output :(", value);
|
||||||
m_can_stream_response = false;
|
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);
|
dbgln_if(JOB_DEBUG, "Job: [{}] = '{}'", name, value);
|
||||||
return;
|
return;
|
||||||
|
@ -341,19 +345,10 @@ void Job::on_socket_connected()
|
||||||
m_current_chunk_remaining_size = size;
|
m_current_chunk_remaining_size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto content_length_header = m_headers.get("Content-Length");
|
deferred_invoke([this] { did_progress(m_content_length, m_received_size); });
|
||||||
Optional<u32> content_length {};
|
|
||||||
|
|
||||||
if (content_length_header.has_value()) {
|
if (m_content_length.has_value()) {
|
||||||
auto length = content_length_header.value().to_uint();
|
auto length = m_content_length.value();
|
||||||
if (length.has_value())
|
|
||||||
content_length = length.value();
|
|
||||||
}
|
|
||||||
|
|
||||||
deferred_invoke([this, content_length] { did_progress(content_length, m_received_size); });
|
|
||||||
|
|
||||||
if (content_length.has_value()) {
|
|
||||||
auto length = content_length.value();
|
|
||||||
if (m_received_size >= length) {
|
if (m_received_size >= length) {
|
||||||
m_received_size = length;
|
m_received_size = length;
|
||||||
finish_up();
|
finish_up();
|
||||||
|
|
|
@ -60,6 +60,7 @@ protected:
|
||||||
size_t m_buffered_size { 0 };
|
size_t m_buffered_size { 0 };
|
||||||
size_t m_received_size { 0 };
|
size_t m_received_size { 0 };
|
||||||
bool m_sent_data { 0 };
|
bool m_sent_data { 0 };
|
||||||
|
Optional<u32> m_content_length;
|
||||||
Optional<ssize_t> m_current_chunk_remaining_size;
|
Optional<ssize_t> m_current_chunk_remaining_size;
|
||||||
Optional<size_t> m_current_chunk_total_size;
|
Optional<size_t> m_current_chunk_total_size;
|
||||||
bool m_can_stream_response { true };
|
bool m_can_stream_response { true };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue