Fix some comments, remove redundant fields etc

This commit is contained in:
Henrik Rydgård
2026-06-13 17:44:26 +02:00
parent 2604e169e1
commit 96ae36b7dd
6 changed files with 12 additions and 13 deletions
+4 -5
View File
@@ -229,8 +229,6 @@ Client::~Client() {
Disconnect(); Disconnect();
} }
// Ignores line folding (deprecated), but respects field combining.
// Don't use for Set-Cookie, which is a special header per RFC 7230.
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value) { bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value) {
std::string search(header); std::string search(header);
search.push_back(':'); search.push_back(':');
@@ -317,7 +315,7 @@ int Client::POST(const RequestParams &req, std::string_view data, std::string_vi
if (mime.empty()) { if (mime.empty()) {
snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\n", (long long)data.size()); snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\n", (long long)data.size());
} else { } else {
snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\nContent-Type: %.*s\r\n", (long long)data.size(), (int)mime.size(), mime.data()); snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\nContent-Type: %.*s\r\n", (long long)data.size(), STR_VIEW(mime));
} }
int err = SendRequestWithData("POST", req, data, otherHeaders, progress); int err = SendRequestWithData("POST", req, data, otherHeaders, progress);
@@ -514,8 +512,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
} }
HTTPRequest::HTTPRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags, net::ResolveFunc customResolve, std::string_view name) HTTPRequest::HTTPRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags, net::ResolveFunc customResolve, std::string_view name)
: Request(method, url, name, &cancelled_, flags), postData_(postData), postMime_(postMime), customResolve_(customResolve) { : Request(method, url, name, outfile, &cancelled_, flags), postData_(postData), postMime_(postMime), customResolve_(customResolve) {
outfile_ = outfile;
} }
HTTPRequest::~HTTPRequest() { HTTPRequest::~HTTPRequest() {
@@ -539,6 +536,8 @@ void HTTPRequest::Join() {
} }
void HTTPRequest::SetFailed(int code) { void HTTPRequest::SetFailed(int code) {
// TODO: Why are we not using code here?
failed_ = true; failed_ = true;
progress_.Update(0, 0, true); progress_.Update(0, 0, true);
completed_ = true; completed_ = true;
+3 -1
View File
@@ -49,6 +49,8 @@ private:
namespace http { namespace http {
// Ignores line folding (deprecated), but respects field combining.
// Don't use for Set-Cookie, which is a special header per RFC 7230.
bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value); bool GetHeaderValue(const std::vector<std::string> &responseHeaders, std::string_view header, std::string *value);
class RequestParams { class RequestParams {
@@ -132,7 +134,7 @@ private:
class CachedRequest : public Request { class CachedRequest : public Request {
public: public:
CachedRequest(RequestMethod method, std::string_view url, std::string_view name, bool *cancelled, RequestFlags flags, std::string_view responseData) CachedRequest(RequestMethod method, std::string_view url, std::string_view name, bool *cancelled, RequestFlags flags, std::string_view responseData)
: Request(method, url, name, cancelled, flags) : Request(method, url, name, Path(), cancelled, flags)
{ {
buffer_.Append(responseData); buffer_.Append(responseData);
} }
+2 -3
View File
@@ -13,8 +13,7 @@
namespace http { namespace http {
HTTPSRequest::HTTPSRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags, std::string_view name) HTTPSRequest::HTTPSRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags flags, std::string_view name)
: Request(method, url, name, &cancelled_, flags), method_(method), postData_(postData), postMime_(postMime) { : Request(method, url, name, outfile, &cancelled_, flags), postData_(postData), postMime_(postMime) {
outfile_ = outfile;
} }
HTTPSRequest::~HTTPSRequest() { HTTPSRequest::~HTTPSRequest() {
@@ -61,7 +60,7 @@ void HTTPSRequest::Join() {
res_ = nullptr; res_ = nullptr;
req_ = nullptr; req_ = nullptr;
} else { } else {
ERROR_LOG(Log::HTTP, "HTTPSDownload::Join not implemented"); ERROR_LOG(Log::HTTP, "HTTPSRequest::Join called before completion");
} }
} }
-1
View File
@@ -25,7 +25,6 @@ public:
bool Failed() const override { return failed_; } bool Failed() const override { return failed_; }
private: private:
RequestMethod method_;
std::string postData_; std::string postData_;
std::string postMime_; std::string postMime_;
bool completed_ = false; bool completed_ = false;
+2 -2
View File
@@ -10,8 +10,8 @@
namespace http { namespace http {
Request::Request(RequestMethod method, std::string_view url, std::string_view name, bool *cancelled, RequestFlags flags) Request::Request(RequestMethod method, std::string_view url, std::string_view name, const Path &outFile, bool *cancelled, RequestFlags flags)
: method_(method), url_(url), name_(name), progress_(cancelled), flags_(flags) { : method_(method), url_(url), name_(name), outfile_(outFile), progress_(cancelled), flags_(flags) {
INFO_LOG(Log::HTTP, "HTTP %s request: %.*s (%.*s)", RequestMethodToString(method), (int)url.size(), url.data(), (int)name.size(), name.data()); INFO_LOG(Log::HTTP, "HTTP %s request: %.*s (%.*s)", RequestMethodToString(method), (int)url.size(), url.data(), (int)name.size(), name.data());
progress_.callback = [this](int64_t bytes, int64_t contentLength, bool done) { progress_.callback = [this](int64_t bytes, int64_t contentLength, bool done) {
+1 -1
View File
@@ -31,7 +31,7 @@ using RequestCompletionCallback = std::function<void(Request &)>;
// Abstract request. // Abstract request.
class Request { class Request {
public: public:
Request(RequestMethod method, std::string_view url, std::string_view name, bool *cancelled, RequestFlags mode); Request(RequestMethod method, std::string_view url, std::string_view name, const Path &outFile, bool *cancelled, RequestFlags mode);
virtual ~Request() {} virtual ~Request() {}
void SetAccept(const char *mime) { void SetAccept(const char *mime) {