HttpConnectionTimeout
HttpConnectionTimeout
#Overview
name: HttpConnectionTimeout
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
It is referenced in 10
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of HttpConnectionTimeout is to set a time limit for establishing a connection in HTTP requests within the Unreal Engine.
This setting variable is primarily used by the HTTP module of Unreal Engine. It is referenced in various parts of the engine, including the core HTTP implementation and test modules.
The value of this variable is set in multiple places:
- In the FHttpModule::StartupModule function, it’s initialized with a default value of 30.0 seconds.
- It can be configured through the engine’s configuration files, as seen in the FHttpModule::UpdateConfigs function.
- It can be manually set in code, as demonstrated in some of the test cases.
HttpConnectionTimeout interacts with other HTTP-related variables such as HttpTotalTimeout, HttpActivityTimeout, HttpReceiveTimeout, and HttpSendTimeout. These variables collectively control various aspects of HTTP request behavior.
Developers should be aware that:
- This timeout specifically applies to the connection establishment phase of an HTTP request.
- It’s separate from other timeouts like the total request timeout or activity timeout.
- The value is used across different platform-specific HTTP implementations (e.g., Apple, Curl).
Best practices when using this variable include:
- Ensure it’s set to a reasonable value based on your network conditions and requirements.
- Consider the relationship between this timeout and other HTTP timeouts to create a coherent request behavior.
- Use the getter method (GetHttpConnectionTimeout()) to access this value in your code rather than accessing the variable directly.
- Be cautious when modifying this value, as it can affect all HTTP requests in your application.
- For fine-grained control, consider using request-specific timeouts when available, rather than relying solely on this global setting.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:31, section: [HTTP]
- INI Section:
HTTP
- Raw value:
30
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Source/Programs/WebTests/Private/TestHttp.cpp:42
Scope (from outer to inner):
file
class class FMockHttpModule : public FHttpModule
Source code excerpt:
{
public:
using FHttpModule::HttpConnectionTimeout;
using FHttpModule::HttpTotalTimeout;
using FHttpModule::HttpActivityTimeout;
};
class FHttpTestLogLevelInitializer
{
#Loc: <Workspace>/Engine/Source/Programs/WebTests/Private/TestHttp.cpp:439
Scope: file
Source code excerpt:
HttpModule->HttpActivityTimeout = 3.0f; // Make sure this won't be triggered before establishing connection
HttpModule->HttpConnectionTimeout = 15.0f;
TSharedRef<IHttpRequest> HttpRequest = CreateRequest();
HttpRequest->SetURL(UrlWithInvalidPortToTestConnectTimeout());
HttpRequest->SetVerb(TEXT("GET"));
#Loc: <Workspace>/Engine/Source/Programs/WebTests/Private/TestHttp.cpp:1004
Scope: file
Source code excerpt:
float TotalTimeoutSetting = 3.0f;
HttpModule->HttpConnectionTimeout = 5.0f;
TSharedPtr<IHttpRequest> HttpRequest = CreateRequest();
HttpRequest->SetURL(UrlMockLatency(10));
HttpRequest->SetVerb(TEXT("GET"));
HttpRequest->SetTimeout(TotalTimeoutSetting);
#Loc: <Workspace>/Engine/Source/Programs/WebTests/Private/TestHttp.cpp:1784
Scope: file
Source code excerpt:
DisableWarningsInThisTest();
HttpModule->HttpConnectionTimeout = 1.0f;
TArray<FString> AltDomains;
AltDomains.Add(UrlToTestMethods());
FHttpRetrySystem::FRetryDomainsPtr RetryDomains = MakeShared<FHttpRetrySystem::FRetryDomains>(MoveTemp(AltDomains));
TSharedRef<IHttpRequest> HttpRequest = HttpRetryManager->CreateRequest(
1/*InRetryLimitCountOverride*/,
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/Apple/AppleHttp.cpp:462
Scope: file
Source code excerpt:
UE_LOG(LogHttp, Verbose, TEXT("FAppleHttpRequest::FAppleHttpRequest()"));
Request = [[NSMutableURLRequest alloc] init];
float HttpConnectionTimeout = FHttpModule::Get().GetHttpConnectionTimeout();
check(HttpConnectionTimeout > 0.0f);
Request.timeoutInterval = HttpConnectionTimeout;
// Disable cache to mimic WinInet behavior
Request.cachePolicy = NSURLRequestReloadIgnoringLocalCacheData;
// Add default headers
const TMap<FString, FString>& DefaultHeaders = FHttpModule::Get().GetDefaultHeaders();
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/Curl/CurlHttp.cpp:983
Scope (from outer to inner):
file
function bool FCurlHttpRequest::SetupRequestHttpThread
Source code excerpt:
// Set connection timeout in seconds
int32 HttpConnectionTimeout = FHttpModule::Get().GetHttpConnectionTimeout();
check(HttpConnectionTimeout > 0);
curl_easy_setopt(EasyHandle, CURLOPT_CONNECTTIMEOUT, HttpConnectionTimeout);
if (FCurlHttpManager::CurlRequestOptions.bAllowSeekFunction && bIsRequestPayloadSeekable)
{
curl_easy_setopt(EasyHandle, CURLOPT_SEEKDATA, this);
curl_easy_setopt(EasyHandle, CURLOPT_SEEKFUNCTION, StaticSeekCallback);
}
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp:53
Scope (from outer to inner):
file
function void FHttpModule::UpdateConfigs
Source code excerpt:
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpTimeout"), HttpActivityTimeout, GEngineIni);
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpTotalTimeout"), HttpTotalTimeout, GEngineIni);
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpConnectionTimeout"), HttpConnectionTimeout, GEngineIni);
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpActivityTimeout"), HttpActivityTimeout, GEngineIni);
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpReceiveTimeout"), HttpReceiveTimeout, GEngineIni);
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpSendTimeout"), HttpSendTimeout, GEngineIni);
GConfig->GetInt(TEXT("HTTP"), TEXT("HttpMaxConnectionsPerServer"), HttpMaxConnectionsPerServer, GEngineIni);
GConfig->GetBool(TEXT("HTTP"), TEXT("bEnableHttp"), bEnableHttp, GEngineIni);
GConfig->GetBool(TEXT("HTTP"), TEXT("bUseNullHttp"), bUseNullHttp, GEngineIni);
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp:87
Scope (from outer to inner):
file
function void FHttpModule::StartupModule
Source code excerpt:
MaxReadBufferSize = 256 * 1024;
HttpTotalTimeout = 0.0f;
HttpConnectionTimeout = 30.0f;
HttpActivityTimeout = 30.0f;
HttpReceiveTimeout = HttpConnectionTimeout;
HttpSendTimeout = HttpConnectionTimeout;
HttpMaxConnectionsPerServer = 16;
bEnableHttp = true;
bUseNullHttp = false;
HttpDelayTime = 0;
HttpThreadActiveFrameTimeInSeconds = 1.0f / 200.0f; // 200Hz
HttpThreadActiveMinimumSleepTimeInSeconds = 0.0f;
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Public/HttpModule.h:112
Scope (from outer to inner):
file
class class FHttpModule : public IModuleInterface, public FSelfRegisteringExec
function inline float GetHttpConnectionTimeout
Source code excerpt:
inline float GetHttpConnectionTimeout() const
{
return HttpConnectionTimeout;
}
/**
* @return timeout in seconds to receive a response on the connection
*/
UE_DEPRECATED(5.4, "GetHttpReceiveTimeout has been deprecated, Use GetHttpActivityTimeout instead to decide if there is still any ongoing activity.")
#Loc: <Workspace>/Engine/Source/Runtime/Online/HTTP/Public/HttpModule.h:337
Scope (from outer to inner):
file
class class FHttpModule : public IModuleInterface, public FSelfRegisteringExec
Source code excerpt:
protected:
/** timeout in seconds to establish the connection */
float HttpConnectionTimeout;
/** timeout in seconds for the entire http request to complete. 0 is no timeout */
float HttpTotalTimeout;
/** timeout in seconds to check there is any ongoing activity on the established connection */
float HttpActivityTimeout;
private: