Files
UnrealEngineUWP/Engine/Source/Runtime/Online/HTTP/Private/HttpModule.cpp
Alex Fennell d10f9953d9 Copying //UE4/Portal-Staging to //UE4/Dev-Main (Source: //UE4/Portal-Staging @ 3138637)
#lockdown Nick.Penwarden, justin.sargent
#rb None

[CL 3138769 by Alex Fennell in Main branch]
2016-09-23 17:31:51 -04:00

167 lines
4.3 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "HttpPrivatePCH.h"
#include "NullHttp.h"
#include "HttpTests.h"
DEFINE_LOG_CATEGORY(LogHttp);
// FHttpModule
IMPLEMENT_MODULE(FHttpModule, HTTP);
FHttpModule* FHttpModule::Singleton = NULL;
void FHttpModule::StartupModule()
{
Singleton = this;
MaxReadBufferSize = 256 * 1024;
FPlatformHttp::Init();
HttpTimeout = 300.0f;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpTimeout"), HttpTimeout, GEngineIni);
HttpConnectionTimeout = -1;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpConnectionTimeout"), HttpConnectionTimeout, GEngineIni);
HttpReceiveTimeout = HttpConnectionTimeout;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpReceiveTimeout"), HttpReceiveTimeout, GEngineIni);
HttpSendTimeout = HttpConnectionTimeout;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpSendTimeout"), HttpSendTimeout, GEngineIni);
HttpMaxConnectionsPerServer = 16;
GConfig->GetInt(TEXT("HTTP"), TEXT("HttpMaxConnectionsPerServer"), HttpMaxConnectionsPerServer, GEngineIni);
bEnableHttp = true;
GConfig->GetBool(TEXT("HTTP"), TEXT("bEnableHttp"), bEnableHttp, GEngineIni);
bUseNullHttp = false;
GConfig->GetBool(TEXT("HTTP"), TEXT("bUseNullHttp"), bUseNullHttp, GEngineIni);
HttpDelayTime = 0;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpDelayTime"), HttpDelayTime, GEngineIni);
HttpThreadProcessingClampInSeconds = 0.005f; // 5ms
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpThreadProcessingClampInSeconds"), HttpThreadProcessingClampInSeconds, GEngineIni);
HttpThreadFrameTimeInSeconds = 1.0f / 30.0f; // 30Hz
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpThreadFrameTimeInSeconds"), HttpThreadFrameTimeInSeconds, GEngineIni);
HttpThreadMinimumSleepTimeInSeconds = 0.0f;
GConfig->GetFloat(TEXT("HTTP"), TEXT("HttpThreadMinimumSleepTimeInSeconds"), HttpThreadMinimumSleepTimeInSeconds, GEngineIni);
HttpManager = FPlatformHttp::CreatePlatformHttpManager();
if (NULL == HttpManager)
{
// platform does not provide specific HTTP manager, use generic one
HttpManager = new FHttpManager();
}
HttpManager->Initialize();
}
void FHttpModule::PostLoadCallback()
{
}
void FHttpModule::PreUnloadCallback()
{
if (HttpManager != nullptr)
{
// block on any http requests that have already been queued up
HttpManager->Flush(true);
}
#if PLATFORM_WINDOWS
extern bool bUseCurl;
if (!bUseCurl)
{
// due to peculiarities of some platforms (notably Windows with WinInet implementation) we need to shutdown platform http first,
// then delete the manager. It is more logical to have reverse order of their creation though. Proper fix
// would be refactoring HTTP platform abstraction to make HttpManager a proper part of it.
FPlatformHttp::Shutdown();
delete HttpManager; // can be passed NULLs
}
else
#endif // PLATFORM_WINDOWS
{
// at least on Linux, the code in HTTP manager (e.g. request destructors) expects platform to be initialized yet
delete HttpManager; // can be passed NULLs
FPlatformHttp::Shutdown();
}
HttpManager = nullptr;
Singleton = nullptr;
}
void FHttpModule::ShutdownModule()
{
}
bool FHttpModule::HandleHTTPCommand(const TCHAR* Cmd, FOutputDevice& Ar)
{
if (FParse::Command(&Cmd, TEXT("TEST")))
{
int32 Iterations=1;
FString IterationsStr;
FParse::Token(Cmd, IterationsStr, true);
if (!IterationsStr.IsEmpty())
{
Iterations = FCString::Atoi(*IterationsStr);
}
FString Url;
FParse::Token(Cmd, Url, true);
if (Url.IsEmpty())
{
Url = TEXT("http://www.google.com");
}
FHttpTest* HttpTest = new FHttpTest(TEXT("GET"),TEXT(""),Url,Iterations);
HttpTest->Run();
}
else if (FParse::Command(&Cmd, TEXT("DUMPREQ")))
{
GetHttpManager().DumpRequests(Ar);
}
return true;
}
bool FHttpModule::Exec(UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar)
{
// Ignore any execs that don't start with HTTP
if (FParse::Command(&Cmd, TEXT("HTTP")))
{
return HandleHTTPCommand( Cmd, Ar );
}
return false;
}
FHttpModule& FHttpModule::Get()
{
if (Singleton == NULL)
{
check(IsInGameThread());
FModuleManager::LoadModuleChecked<FHttpModule>("HTTP");
}
check(Singleton != NULL);
return *Singleton;
}
TSharedRef<IHttpRequest> FHttpModule::CreateRequest()
{
if (bUseNullHttp)
{
return TSharedRef<IHttpRequest>(new FNullHttpRequest());
}
else
{
// Create the platform specific Http request instance
return TSharedRef<IHttpRequest>(FPlatformHttp::ConstructRequest());
}
}