diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index 786975bb33..142f41426d 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -509,7 +509,7 @@ int Download::PerformGET(const std::string &url) { return -1; } - RequestParams req(fileUrl.Resource(), "*/*"); + RequestParams req(fileUrl.Resource(), acceptMime_); return client.GET(req, &buffer_, responseHeaders_, &progress_); } @@ -571,8 +571,10 @@ void Download::Do() { completed_ = true; } -std::shared_ptr Downloader::StartDownload(const std::string &url, const Path &outfile) { +std::shared_ptr Downloader::StartDownload(const std::string &url, const Path &outfile, const char *acceptMime) { std::shared_ptr dl(new Download(url, outfile)); + if (acceptMime) + dl->SetAccept(acceptMime); downloads_.push_back(dl); dl->Start(); return dl; @@ -581,8 +583,11 @@ std::shared_ptr Downloader::StartDownload(const std::string &url, cons std::shared_ptr Downloader::StartDownloadWithCallback( const std::string &url, const Path &outfile, - std::function callback) { + std::function callback, + const char *acceptMime) { std::shared_ptr dl(new Download(url, outfile)); + if (acceptMime) + dl->SetAccept(acceptMime); dl->SetCallback(callback); downloads_.push_back(dl); dl->Start(); diff --git a/Common/Net/HTTPClient.h b/Common/Net/HTTPClient.h index 8146353b2f..e96102ce05 100644 --- a/Common/Net/HTTPClient.h +++ b/Common/Net/HTTPClient.h @@ -120,6 +120,10 @@ public: std::string url() const { return url_; } const Path &outfile() const { return outfile_; } + void SetAccept(const char *mime) { + acceptMime_ = mime; + } + // If not downloading to a file, access this to get the result. Buffer &buffer() { return buffer_; } const Buffer &buffer() const { return buffer_; } @@ -160,6 +164,7 @@ private: std::string url_; Path outfile_; std::thread thread_; + const char *acceptMime_ = "*/*"; int resultCode_ = 0; bool completed_ = false; bool failed_ = false; @@ -177,12 +182,13 @@ public: CancelAll(); } - std::shared_ptr StartDownload(const std::string &url, const Path &outfile); + std::shared_ptr StartDownload(const std::string &url, const Path &outfile, const char *acceptMime = nullptr); std::shared_ptr StartDownloadWithCallback( const std::string &url, const Path &outfile, - std::function callback); + std::function callback, + const char *acceptMime = nullptr); // Drops finished downloads from the list. void Update(); diff --git a/Core/Config.cpp b/Core/Config.cpp index fa8d232dc6..bb956d8c86 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1393,8 +1393,9 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { // splash screen quickly), but then we'll just show the notification next time instead, we store the // upgrade number in the ini. if (iRunCount % 10 == 0 && bCheckForNewVersion) { - std::shared_ptr dl = g_DownloadManager.StartDownloadWithCallback( - "http://www.ppsspp.org/version.json", Path(), &DownloadCompletedCallback); + const char *versionUrl = "http://www.ppsspp.org/version.json"; + const char *acceptMime = "application/json, text/*; q=0.9, */*; q=0.8"; + auto dl = g_DownloadManager.StartDownloadWithCallback(versionUrl, Path(), &DownloadCompletedCallback, acceptMime); dl->SetHidden(true); } diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 26b0581c95..bb658b2219 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -100,7 +100,8 @@ bool GameManager::DownloadAndInstall(std::string storeFileUrl) { } Path filename = GetTempFilename(); - curDownload_ = g_DownloadManager.StartDownload(storeFileUrl, filename); + const char *acceptMime = "application/zip, application/x-cso, application/x-iso9660-image, application/octet-stream; q=0.9, */*; q=0.8"; + curDownload_ = g_DownloadManager.StartDownload(storeFileUrl, filename, acceptMime); return true; } diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index fdd15ccb42..389fdf0967 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -1206,7 +1206,8 @@ void FrameDumpTestScreen::update() { UIScreen::update(); if (!listing_) { - listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path()); + const char *acceptMime = "text/html, */*; q=0.8"; + listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path(), acceptMime); } if (listing_ && listing_->Done() && files_.empty()) { diff --git a/UI/Store.cpp b/UI/Store.cpp index 4f029d9738..ab40825e93 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -134,7 +134,9 @@ void HttpImageFileView::DownloadCompletedCallback(http::Download &download) { void HttpImageFileView::Draw(UIContext &dc) { using namespace Draw; if (!texture_ && !textureFailed_ && !path_.empty() && !download_) { - download_ = downloader_->StartDownloadWithCallback(path_, Path(), std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1)); + auto cb = std::bind(&HttpImageFileView::DownloadCompletedCallback, this, std::placeholders::_1); + const char *acceptMime = "image/png, image/jpeg, image/*; q=0.9, */*; q=0.8"; + download_ = downloader_->StartDownloadWithCallback(path_, Path(), cb, acceptMime); download_->SetHidden(true); } @@ -366,8 +368,8 @@ StoreScreen::StoreScreen() { loading_ = true; std::string indexPath = storeBaseUrl + "index.json"; - - listing_ = g_DownloadManager.StartDownload(indexPath, Path()); + const char *acceptMime = "application/json, */*; q=0.8"; + listing_ = g_DownloadManager.StartDownload(indexPath, Path(), acceptMime); } StoreScreen::~StoreScreen() {