HTTP user agent plumbing

This commit is contained in:
Henrik Rydgård
2023-07-14 15:24:34 +02:00
parent bf05fe22b1
commit 84d9b7e75d
3 changed files with 22 additions and 1 deletions
+11 -1
View File
@@ -180,7 +180,7 @@ void Connection::Disconnect() {
namespace http {
// TODO: do something sane here
constexpr const char *DEFAULT_USERAGENT = "NATIVEAPP 1.0";
constexpr const char *DEFAULT_USERAGENT = "PPSSPP";
Client::Client() {
httpVersion_ = "1.1";
@@ -491,6 +491,10 @@ int Download::Perform(const std::string &url) {
}
http::Client client;
if (!userAgent_.empty()) {
client.SetUserAgent(userAgent_);
}
if (!client.Resolve(fileUrl.Host().c_str(), fileUrl.Port())) {
ERROR_LOG(IO, "Failed resolving %s", url.c_str());
return -1;
@@ -580,6 +584,8 @@ void Download::Do() {
std::shared_ptr<Download> Downloader::StartDownload(const std::string &url, const Path &outfile, const char *acceptMime) {
std::shared_ptr<Download> dl(new Download(RequestMethod::GET, url, "", "", outfile));
if (!userAgent_.empty())
dl->SetUserAgent(userAgent_);
if (acceptMime)
dl->SetAccept(acceptMime);
newDownloads_.push_back(dl);
@@ -593,6 +599,8 @@ std::shared_ptr<Download> Downloader::StartDownloadWithCallback(
std::function<void(Download &)> callback,
const char *acceptMime) {
std::shared_ptr<Download> dl(new Download(RequestMethod::GET, url, "", "", outfile));
if (!userAgent_.empty())
dl->SetUserAgent(userAgent_);
if (acceptMime)
dl->SetAccept(acceptMime);
dl->SetCallback(callback);
@@ -607,6 +615,8 @@ std::shared_ptr<Download> Downloader::AsyncPostWithCallback(
const std::string &postMime,
std::function<void(Download &)> callback) {
std::shared_ptr<Download> dl(new Download(RequestMethod::POST, url, postData, postMime, Path()));
if (!userAgent_.empty())
dl->SetUserAgent(userAgent_);
dl->SetCallback(callback);
newDownloads_.push_back(dl);
dl->Start();