diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-05-03 09:01:06 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-03 12:59:26 +0200 |
commit | 06cf9d3fb7fd712c50a720e22309b91084b9e5e9 (patch) | |
tree | fd226b3e5fbdd0bc32715503378db18278477c6b /Libraries/LibHTTP | |
parent | c6825a96c74bb6222aaa7e82c9950290f5e7471b (diff) | |
download | serenity-06cf9d3fb7fd712c50a720e22309b91084b9e5e9.zip |
ProtocolServer: Implement and handle download progress
Also updates `pro` to display download progress and speed on stderr
Diffstat (limited to 'Libraries/LibHTTP')
-rw-r--r-- | Libraries/LibHTTP/HttpJob.cpp | 18 | ||||
-rw-r--r-- | Libraries/LibHTTP/HttpsJob.cpp | 21 |
2 files changed, 30 insertions, 9 deletions
diff --git a/Libraries/LibHTTP/HttpJob.cpp b/Libraries/LibHTTP/HttpJob.cpp index 8b1b0e8c9d..41a90b324e 100644 --- a/Libraries/LibHTTP/HttpJob.cpp +++ b/Libraries/LibHTTP/HttpJob.cpp @@ -156,11 +156,23 @@ void HttpJob::on_socket_connected() m_received_size += payload.size(); auto content_length_header = m_headers.get("Content-Length"); + Optional<u32> content_length {}; + if (content_length_header.has_value()) { bool ok; - auto content_length = content_length_header.value().to_uint(ok); - if (ok && m_received_size >= content_length) { - m_received_size = content_length; + auto length = content_length_header.value().to_uint(ok); + if (ok) + content_length = length; + } + + deferred_invoke([this, content_length](auto&) { + did_progress(content_length, m_received_size); + }); + + if (content_length.has_value()) { + auto length = content_length.value(); + if (m_received_size >= length) { + m_received_size = length; finish_up(); } } diff --git a/Libraries/LibHTTP/HttpsJob.cpp b/Libraries/LibHTTP/HttpsJob.cpp index c35575d025..aaa9944ab2 100644 --- a/Libraries/LibHTTP/HttpsJob.cpp +++ b/Libraries/LibHTTP/HttpsJob.cpp @@ -166,16 +166,25 @@ void HttpsJob::on_socket_connected() m_received_size += payload.size(); auto content_length_header = m_headers.get("Content-Length"); + Optional<u32> content_length {}; + if (content_length_header.has_value()) { bool ok; - auto content_length = content_length_header.value().to_uint(ok); - if (ok && m_received_size >= content_length) { - m_received_size = content_length; + auto length = content_length_header.value().to_uint(ok); + if (ok) + content_length = length; + } + + // This needs to be synchronous + // FIXME: Somehow enforce that this should not modify anything + did_progress(content_length, m_received_size); + + if (content_length.has_value()) { + auto length = content_length.value(); + if (m_received_size >= length) { + m_received_size = length; finish_up(); } - } else { - // no content-length, assume closed connection - finish_up(); } }; } |