From 2604e169e1c747aecf44b0707e4500fed146fd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sat, 13 Jun 2026 17:18:35 +0200 Subject: [PATCH] Make progress optional in some function to avoid flouting convention --- Common/Net/HTTPClient.cpp | 29 +++++++++++++++++++---------- Common/Net/HTTPClient.h | 6 +++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index fa9bc4b116..2596b7dd3c 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -348,7 +348,9 @@ int Client::SendRequest(const char *method, const RequestParams &req, const char } int Client::SendRequestWithData(const char *method, const RequestParams &req, std::string_view data, const char *otherHeaders, net::RequestProgress *progress) { - progress->Update(0, 0, false); + if (progress) { + progress->Update(0, 0, false); + } net::Buffer buffer; const char *tpl = @@ -367,7 +369,7 @@ int Client::SendRequestWithData(const char *method, const RequestParams &req, st req.acceptMime, otherHeaders ? otherHeaders : ""); buffer.Append(data); - bool flushed = buffer.FlushSocket(sock(), dataTimeout_, progress->cancelled); + bool flushed = buffer.FlushSocket(sock(), headerTimeout_, progress ? progress->cancelled : nullptr); if (!flushed) { return -1; // TODO error code. } @@ -378,9 +380,9 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & // Snarf all the data we can into RAM. A little unsafe but hey. static constexpr float CANCEL_INTERVAL = 0.25f; bool ready = false; - double endTimeout = time_now_d() + dataTimeout_; + double endTimeout = time_now_d() + headerTimeout_; while (!ready) { - if (progress->cancelled && *progress->cancelled) + if (progress && progress->cancelled && *progress->cancelled) return -1; ready = fd_util::WaitUntilReady(sock(), CANCEL_INTERVAL, false); if (!ready && time_now_d() > endTimeout) { @@ -417,15 +419,16 @@ int Client::ReadResponseHeaders(net::Buffer *readbuf, std::vector & return -1; } - if (statusLine) - *statusLine = line; + if (statusLine) { + *statusLine = std::move(line); + } while (true) { int sz = readbuf->TakeLineCRLF(&line); if (!sz || sz < 0) break; VERBOSE_LOG(Log::HTTP, "Header line: %s", line.c_str()); - responseHeaders.push_back(line); + responseHeaders.emplace_back(line); } if (responseHeaders.size() == 0) { @@ -479,7 +482,9 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vectorUpdate(0, 0, true); + if (progress) { + progress->Update(0, 0, true); + } return -1; } } else { @@ -493,14 +498,18 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vectorUpdate(0, 0, true); + if (progress) { + progress->Update(0, 0, true); + } return -1; } output->Append(decompressed); } } - progress->Update(contentLength, contentLength, true); + if (progress) { + progress->Update(contentLength, contentLength, true); + } return 0; } diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index 607715086e..fed7ab307c 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -27,7 +27,7 @@ public: bool Connect(int maxTries = 2, double timeout = 20.0f, bool *cancelConnect = nullptr); void Disconnect(); - // Only to be used for bring-up and debugging. + // TODO: Try to expose this less. uintptr_t sock() const { return sock_; } std::string GetLocalIpAsString() const; @@ -83,7 +83,7 @@ public: int ReadResponseEntity(net::Buffer *readbuf, const std::vector &responseHeaders, Buffer *output, net::RequestProgress *progress); void SetDataTimeout(double t) { - dataTimeout_ = t; + headerTimeout_ = t; } void SetUserAgent(std::string_view value) { @@ -97,7 +97,7 @@ public: protected: std::string userAgent_; const char* httpVersion_; - double dataTimeout_ = 900.0; + double headerTimeout_ = 900.0; }; // Really an asynchronous request.