http.DefaultUserAgentCommentsEnabled
http.DefaultUserAgentCommentsEnabled
#Overview
name: http.DefaultUserAgentCommentsEnabled
This variable is created as a Console Variable (cvar).
- type:
Var
- help:
Whether comments are supported in the defualt user agent string
It is referenced in 7
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of http.DefaultUserAgentCommentsEnabled is to control whether comments are included in the default user agent string for HTTP requests in Unreal Engine 5. This setting is primarily used in the HTTP module and the Analytics subsystem.
The Unreal Engine subsystems that rely on this setting variable are:
- The HTTP module (Runtime/Online/HTTP)
- The Analytics subsystem (Runtime/Analytics/AnalyticsET)
The value of this variable is set using a TAutoConsoleVariable in the GenericPlatformHttp.cpp file. It is initialized with a default value of true, meaning comments are enabled by default in the user agent string.
This variable interacts with the associated variable CVarDefaultUserAgentCommentsEnabled, which is used in the Analytics subsystem. They share the same value and purpose but are used in different contexts.
Developers must be aware that:
- Changing this variable will affect the content of the user agent string in HTTP requests.
- It can be modified at runtime and will take effect immediately.
- The setting is saved for the next boot, so changes persist across engine restarts.
Best practices when using this variable include:
- Consider the implications of including or excluding comments in the user agent string for privacy and security reasons.
- Use the associated configuration settings in the GEngineIni file to control which specific comments are allowed when the variable is enabled.
- Be consistent across your project in how you handle user agent strings to maintain a uniform approach to HTTP requests.
Regarding the associated variable CVarDefaultUserAgentCommentsEnabled:
The purpose of CVarDefaultUserAgentCommentsEnabled is similar to http.DefaultUserAgentCommentsEnabled, but it is specifically used in the Analytics subsystem to control whether comments are included in the analytics user agent string.
This variable is used in the AnalyticsET module to determine whether to include project and platform comments in the analytics user agent string. It affects the behavior of the FAnalyticsUserAgentCache class, which is responsible for building and caching the user agent string for analytics purposes.
The value of this variable is also set using a TAutoConsoleVariable in the IAnalyticsProviderET.cpp file, with a default value of true.
Developers should be aware that:
- This variable specifically affects analytics-related user agent strings, separate from general HTTP requests.
- It interacts with configuration settings in the GEngineIni file to determine which project and platform comments are allowed.
Best practices for using this variable include:
- Coordinate its use with the http.DefaultUserAgentCommentsEnabled variable to maintain consistency in user agent handling across the engine.
- Carefully consider which project and platform comments should be included in analytics data, balancing the need for information with privacy concerns.
- Use the AllowedUserAgentProjectComments and AllowedUserAgentPlatformComments settings in the GEngineIni file to fine-tune which comments are included when this variable is enabled.
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:14
Scope: file
Source code excerpt:
TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
TEXT("http.DefaultUserAgentCommentsEnabled"),
true,
TEXT("Whether comments are supported in the defualt user agent string"),
ECVF_SaveForNextBoot
);
namespace
#Associated Variable and Callsites
This variable is associated with another variable named CVarDefaultUserAgentCommentsEnabled
. They share the same value. See the following C++ source code.
#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:29
Scope (from outer to inner):
file
namespace AnalyticsProviderETCvars
Source code excerpt:
TEXT("AnalyticsET.PreventMultipleFlushesInOneFrame"),
PreventMultipleFlushesInOneFrame,
TEXT("When true, prevents more than one AnalyticsProviderET instance from flushing in the same frame, allowing the flush and HTTP cost to be amortized.")
);
TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
TEXT("AnalyticsET.UserAgentCommentsEnabled"),
true,
TEXT("Whether comments are supported in the analytics user agent string"),
ECVF_SaveForNextBoot
);
}
// Want to avoid putting the project name into the User-Agent, because for some apps (like the editor), the project name is private info.
// The analytics User-Agent uses the default User-Agent, but with project name removed.
class FAnalyticsUserAgentCache
{
#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:73
Scope (from outer to inner):
file
class class FAnalyticsUserAgentCache
function static TSet<FString> GetAllowedProjectComments
Source code excerpt:
}
static TSet<FString> GetAllowedProjectComments()
{
TArray<FString> AllowedProjectComments;
if (AnalyticsProviderETCvars::CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
{
GConfig->GetArray(TEXT("Analytics"), TEXT("AllowedUserAgentProjectComments"), AllowedProjectComments, GEngineIni);
}
return TSet<FString>(MoveTemp(AllowedProjectComments));
}
static TSet<FString> GetAllowedPlatformComments()
{
TArray<FString> AllowedPlatformComments;
if (AnalyticsProviderETCvars::CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
{
GConfig->GetArray(TEXT("Analytics"), TEXT("AllowedUserAgentPlatformComments"), AllowedPlatformComments, GEngineIni);
}
return TSet<FString>(MoveTemp(AllowedPlatformComments));
}
static TSet<FString> ParseCommentSet(const FString& CommentBlob)
{
TArray<FString> Comments;
CommentBlob.ParseIntoArray(Comments, TEXT(";"));
return TSet<FString>(MoveTemp(Comments));
#Loc: <Workspace>/Engine/Source/Runtime/Analytics/AnalyticsET/Private/IAnalyticsProviderET.cpp:83
Scope (from outer to inner):
file
class class FAnalyticsUserAgentCache
function static TSet<FString> GetAllowedPlatformComments
Source code excerpt:
{
TArray<FString> AllowedPlatformComments;
if (AnalyticsProviderETCvars::CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
{
GConfig->GetArray(TEXT("Analytics"), TEXT("AllowedUserAgentPlatformComments"), AllowedPlatformComments, GEngineIni);
}
return TSet<FString>(MoveTemp(AllowedPlatformComments));
}
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:10
Scope: file
Source code excerpt:
#include "Misc/EngineVersion.h"
#include "Misc/App.h"
#include "Misc/ScopeRWLock.h"
#include "String/BytesToHex.h"
TAutoConsoleVariable<bool> CVarDefaultUserAgentCommentsEnabled(
TEXT("http.DefaultUserAgentCommentsEnabled"),
true,
TEXT("Whether comments are supported in the defualt user agent string"),
ECVF_SaveForNextBoot
);
namespace
{
/**
* Utility to split stringviews based on a substring. Returns everything before SplitString as 'Left' and everything after as
* 'Right'. If SplitString is not found, OutLeft and OutRight are not modified and the function will return false.
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:231
Scope (from outer to inner):
file
class class FUserAgentImpl final
function FUserAgentImpl
Source code excerpt:
FUserAgentImpl()
: RWLock()
, bCachedCommentsEnabled(false)
{
CachedUserAgent = BuildUserAgentString();
CVarDefaultUserAgentCommentsEnabled->OnChangedDelegate().AddRaw(this, &FUserAgentImpl::OnCommentsEnabledChanged);
}
void AddProjectComment(const FString& Comment)
{
FRWScopeLock WriteLock(RWLock, SLT_Write);
Builder.AddProjectComment(Comment);
CachedUserAgent = BuildUserAgentString();
}
void AddPlatformComment(const FString& Comment)
{
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/GenericPlatformHttp.cpp:268
Scope (from outer to inner):
file
class class FUserAgentImpl final
function FString BuildUserAgentString
Source code excerpt:
}
private:
FString BuildUserAgentString()
{
if (CVarDefaultUserAgentCommentsEnabled.GetValueOnAnyThread())
{
return Builder.BuildUserAgentString();
}
else
{
// Build the user agent string without any comments.
TSet<FString> AllowedCommentsFilter;
return Builder.BuildUserAgentString(&AllowedCommentsFilter, &AllowedCommentsFilter);
}
}