HTTP: Replace ProgressBarMode with a new RequestFlags enum

This commit is contained in:
Henrik Rydgård
2025-01-23 12:09:56 +01:00
parent 5c0553031e
commit eb719c43e8
14 changed files with 53 additions and 56 deletions
+7 -6
View File
@@ -299,13 +299,14 @@ int Client::GET(const RequestParams &req, Buffer *output, net::RequestProgress *
return code;
}
int Client::POST(const RequestParams &req, const std::string &data, const std::string &mime, Buffer *output, net::RequestProgress *progress) {
int Client::POST(const RequestParams &req, std::string_view data, std::string_view mime, Buffer *output, net::RequestProgress *progress) {
char otherHeaders[2048];
if (mime.empty()) {
snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\n", (long long)data.size());
} else {
snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\nContent-Type: %s\r\n", (long long)data.size(), mime.c_str());
snprintf(otherHeaders, sizeof(otherHeaders), "Content-Length: %lld\r\nContent-Type: %.*s\r\n", (long long)data.size(), (int)mime.size(), mime.data());
}
int err = SendRequestWithData("POST", req, data, otherHeaders, progress);
if (err < 0) {
return err;
@@ -325,7 +326,7 @@ int Client::POST(const RequestParams &req, const std::string &data, const std::s
return code;
}
int Client::POST(const RequestParams &req, const std::string &data, Buffer *output, net::RequestProgress *progress) {
int Client::POST(const RequestParams &req, std::string_view data, Buffer *output, net::RequestProgress *progress) {
return POST(req, data, "", output, progress);
}
@@ -333,7 +334,7 @@ int Client::SendRequest(const char *method, const RequestParams &req, const char
return SendRequestWithData(method, req, "", otherHeaders, progress);
}
int Client::SendRequestWithData(const char *method, const RequestParams &req, const std::string &data, const char *otherHeaders, net::RequestProgress *progress) {
int Client::SendRequestWithData(const char *method, const RequestParams &req, std::string_view data, const char *otherHeaders, net::RequestProgress *progress) {
progress->Update(0, 0, false);
net::Buffer buffer;
@@ -485,7 +486,7 @@ int Client::ReadResponseEntity(net::Buffer *readbuf, const std::vector<std::stri
return 0;
}
HTTPRequest::HTTPRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, ProgressBarMode progressBarMode, std::string_view name)
HTTPRequest::HTTPRequest(RequestMethod method, std::string_view url, std::string_view postData, std::string_view postMime, const Path &outfile, RequestFlags progressBarMode, std::string_view name)
: Request(method, url, name, &cancelled_, progressBarMode), postData_(postData), postMime_(postMime) {
outfile_ = outfile;
}
@@ -612,4 +613,4 @@ void HTTPRequest::Do() {
completed_ = true;
}
} // http
} // namespace http