mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 16:13:46 +01:00
Minimize data sent in the default user agent (#14851)
This commit is contained in:
parent
eba0806d77
commit
a7a719261e
@ -40,10 +40,17 @@ static std::unordered_map<u64, std::queue<HTTPFetchResult>>
|
|||||||
g_httpfetch_results;
|
g_httpfetch_results;
|
||||||
static PcgRandom g_callerid_randomness;
|
static PcgRandom g_callerid_randomness;
|
||||||
|
|
||||||
|
static std::string default_user_agent()
|
||||||
|
{
|
||||||
|
std::string ret(PROJECT_NAME_C "/");
|
||||||
|
ret.append(g_version_string).append(" (").append(porting::get_sysinfo()).append(")");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
HTTPFetchRequest::HTTPFetchRequest() :
|
HTTPFetchRequest::HTTPFetchRequest() :
|
||||||
timeout(g_settings->getS32("curl_timeout")),
|
timeout(g_settings->getS32("curl_timeout")),
|
||||||
connect_timeout(10 * 1000),
|
connect_timeout(10 * 1000),
|
||||||
useragent(std::string(PROJECT_NAME_C "/") + g_version_hash + " (" + porting::get_sysinfo() + ")")
|
useragent(default_user_agent())
|
||||||
{
|
{
|
||||||
timeout = std::max(timeout, MIN_HTTPFETCH_TIMEOUT_INTERACTIVE);
|
timeout = std::max(timeout, MIN_HTTPFETCH_TIMEOUT_INTERACTIVE);
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#endif
|
#endif
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
#include "porting_android.h"
|
#include "porting_android.h"
|
||||||
|
#include <android/api-level.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
@ -205,7 +206,10 @@ bool detectMSVCBuildDir(const std::string &path)
|
|||||||
return (!removeStringEnd(path, ends).empty());
|
return (!removeStringEnd(path, ends).empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_sysinfo()
|
// Note that the system info is sent in every HTTP request, so keep it reasonably
|
||||||
|
// privacy-conserving while ideally still being meaningful.
|
||||||
|
|
||||||
|
static std::string detectSystemInfo()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
@ -251,14 +255,34 @@ std::string get_sysinfo()
|
|||||||
delete[] filePath;
|
delete[] filePath;
|
||||||
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
#else
|
#elif defined(__ANDROID__)
|
||||||
|
std::ostringstream oss;
|
||||||
struct utsname osinfo;
|
struct utsname osinfo;
|
||||||
uname(&osinfo);
|
uname(&osinfo);
|
||||||
return std::string(osinfo.sysname) + "/"
|
int api = android_get_device_api_level();
|
||||||
+ osinfo.release + " " + osinfo.machine;
|
|
||||||
|
oss << "Android/" << api << " " << osinfo.machine;
|
||||||
|
return oss.str();
|
||||||
|
#else /* POSIX */
|
||||||
|
struct utsname osinfo;
|
||||||
|
uname(&osinfo);
|
||||||
|
|
||||||
|
std::string_view release(osinfo.release);
|
||||||
|
// cut off anything but the primary version number
|
||||||
|
release = release.substr(0, release.find_first_not_of("0123456789."));
|
||||||
|
|
||||||
|
std::string ret = osinfo.sysname;
|
||||||
|
ret.append("/").append(release).append(" ").append(osinfo.machine);
|
||||||
|
return ret;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string &get_sysinfo()
|
||||||
|
{
|
||||||
|
static std::string ret = detectSystemInfo();
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool getCurrentWorkingDir(char *buf, size_t len)
|
bool getCurrentWorkingDir(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
|
@ -138,7 +138,7 @@ void initializePaths();
|
|||||||
Return system information
|
Return system information
|
||||||
e.g. "Linux/3.12.7 x86_64"
|
e.g. "Linux/3.12.7 x86_64"
|
||||||
*/
|
*/
|
||||||
std::string get_sysinfo();
|
const std::string &get_sysinfo();
|
||||||
|
|
||||||
|
|
||||||
// Monotonic timer
|
// Monotonic timer
|
||||||
|
Loading…
Reference in New Issue
Block a user