diff --git a/Userland/Libraries/LibHTTP/Job.cpp b/Userland/Libraries/LibHTTP/Job.cpp index 8b67de60a1..6ead5fad10 100644 --- a/Userland/Libraries/LibHTTP/Job.cpp +++ b/Userland/Libraries/LibHTTP/Job.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -352,6 +353,14 @@ void Job::on_socket_connected() }); } +void Job::timer_event(Core::TimerEvent& event) +{ + event.accept(); + finish_up(); + if (m_buffered_size == 0) + stop_timer(); +} + void Job::finish_up() { m_state = State::Finished; @@ -382,9 +391,9 @@ void Job::finish_up() // before we can actually call `did_finish`. in a normal flow, this should // never be hit since the client is reading as we are writing, unless there // are too many concurrent downloads going on. - deferred_invoke([this](auto&) { - finish_up(); - }); + dbgln_if(JOB_DEBUG, "Flush finished with {} bytes remaining, will try again later", m_buffered_size); + if (!has_timer()) + start_timer(50); return; } diff --git a/Userland/Libraries/LibHTTP/Job.h b/Userland/Libraries/LibHTTP/Job.h index f878a4e8c5..83fcfd9613 100644 --- a/Userland/Libraries/LibHTTP/Job.h +++ b/Userland/Libraries/LibHTTP/Job.h @@ -42,6 +42,7 @@ protected: virtual bool is_established() const = 0; virtual bool should_fail_on_empty_payload() const { return true; } virtual void read_while_data_available(Function read) { read(); }; + virtual void timer_event(Core::TimerEvent&) override; enum class State { InStatus,