HTTP user agent plumbing

This commit is contained in:
Henrik Rydgård committed 2023-07-14 15:24:34 +02:00
1 parent bf05fe22b1
commit 84d9b7e75d
3 files changed
+22 -1

No files matched your search

+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();
+9
View File
@@ -156,6 +156,9 @@ public:
// Downloader::GetCurrentProgress won't return it in the results.
bool IsHidden() const { return hidden_; }
void SetHidden(bool hidden) { hidden_ = hidden; }
void SetUserAgent(const std::string &userAgent) {
userAgent_ = userAgent;
}
private:
void Do(); // Actually does the download. Runs on thread.
@@ -166,6 +169,7 @@ private:
RequestProgress progress_;
RequestMethod method_;
std::string postData_;
std::string userAgent_;
Buffer buffer_;
std::vector<std::string> responseHeaders_;
std::string url_;
@@ -209,6 +213,9 @@ public:
void CancelAll();
void WaitForAll();
void SetUserAgent(const std::string &userAgent) {
userAgent_ = userAgent;
}
std::vector<float> GetCurrentProgress();
@@ -221,6 +228,8 @@ private:
// These get copied to downloads_ in Update(). It's so that callbacks can add new downloads
// while running.
std::vector<std::shared_ptr<Download>> newDownloads_;
std::string userAgent_;
};
} // http
+2
View File
@@ -1050,6 +1050,8 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
bUpdatedInstanceCounter = true;
}
g_DownloadManager.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION));
UpdateIniLocation(iniFileName, controllerIniFilename);
INFO_LOG(LOADER, "Loading config: %s", iniFilename_.c_str());