Files
UnrealEngineUWP/Engine/Source/Runtime/Online/HTTP/Private/GenericPlatform/HttpRequestCommon.cpp
lorry li c463f2cc23 Sync http request status into http response status, so user code can write different handling cases for different status, even if user keep the response after request get destroyed.
[REVIEW] [at]michael.kirzinger
#jira UE-197946
#rb Michael.Kirzinger
#tests Tried with game client, also passed auto test project WebTests.

[CL 29800763 by lorry li in ue5-main branch]
2023-11-16 21:27:48 -05:00

83 lines
2.3 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "GenericPlatform/HttpRequestCommon.h"
#include "GenericPlatform/HttpResponseCommon.h"
#include "Http.h"
#include "HttpManager.h"
FString FHttpRequestCommon::GetURLParameter(const FString& ParameterName) const
{
FString ReturnValue;
if (TOptional<FString> OptionalParameterValue = FGenericPlatformHttp::GetUrlParameter(GetURL(), ParameterName))
{
ReturnValue = MoveTemp(OptionalParameterValue.GetValue());
}
return ReturnValue;
}
EHttpRequestStatus::Type FHttpRequestCommon::GetStatus() const
{
return CompletionStatus;
}
bool FHttpRequestCommon::PreCheck() const
{
// Prevent overlapped requests using the same instance
if (CompletionStatus == EHttpRequestStatus::Processing)
{
UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. Still processing last request."));
return false;
}
// Nothing to do without a valid URL
if (GetURL().IsEmpty())
{
UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. No URL was specified."));
return false;
}
if (GetVerb().IsEmpty())
{
UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. No Verb was specified."));
return false;
}
// Make sure the URL is parsed correctly with a valid HTTP scheme
const FString URL = GetURL();
if (!URL.StartsWith(TEXT("http://")) && !URL.StartsWith(TEXT("https://")))
{
UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. URL '%s' is not a valid HTTP request."), *GetURL());
return false;
}
if (!FHttpModule::Get().GetHttpManager().IsDomainAllowed(GetURL()))
{
UE_LOG(LogHttp, Warning, TEXT("ProcessRequest failed. URL '%s' is not using an allowed domain."), *GetURL());
return false;
}
return true;
}
void FHttpRequestCommon::SetDelegateThreadPolicy(EHttpRequestDelegateThreadPolicy InDelegateThreadPolicy)
{
DelegateThreadPolicy = InDelegateThreadPolicy;
}
EHttpRequestDelegateThreadPolicy FHttpRequestCommon::GetDelegateThreadPolicy() const
{
return DelegateThreadPolicy;
}
void FHttpRequestCommon::SetStatus(EHttpRequestStatus::Type InCompletionStatus)
{
CompletionStatus = InCompletionStatus;
if (FHttpResponsePtr Response = GetResponse())
{
TSharedPtr<FHttpResponseCommon> ResponseCommon = StaticCastSharedPtr<FHttpResponseCommon>(Response);
ResponseCommon->SetRequestStatus(InCompletionStatus);
}
}