You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
#jira UE-155145 #review-24037950 @jake.niman @michael.kirzinger @rob.cannaday #preflight 63e268181466610c64972e28 [CL 24048638 by lorry li in ue5-main branch]
61 lines
2.5 KiB
C++
61 lines
2.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "HttpServerResponse.h"
|
|
#include "HttpServerConstants.h"
|
|
#include "HttpServerConstantsPrivate.h"
|
|
|
|
TUniquePtr<FHttpServerResponse> FHttpServerResponse::Create(const FString& Text, FString ContentType)
|
|
{
|
|
TUniquePtr<FHttpServerResponse> Response = MakeUnique<FHttpServerResponse>();
|
|
Response->Code = EHttpServerResponseCodes::Ok;
|
|
|
|
FTCHARToUTF8 ConvertToUtf8(*Text);
|
|
const uint8* ConvertToUtf8Bytes = (reinterpret_cast<const uint8*>(ConvertToUtf8.Get()));
|
|
Response->Body.Append(ConvertToUtf8Bytes, ConvertToUtf8.Length());
|
|
|
|
FString Utf8CharsetContentType = FString::Printf(TEXT("%s;charset=utf-8"), *ContentType);
|
|
TArray<FString> ContentTypeValue = { MoveTemp(Utf8CharsetContentType) };
|
|
Response->Headers.Add(UE_HTTP_SERVER_HEADER_KEYS_CONTENT_TYPE, MoveTemp(ContentTypeValue));
|
|
|
|
return Response;
|
|
}
|
|
|
|
TUniquePtr<FHttpServerResponse> FHttpServerResponse::Create(TArray<uint8>&& RawBytes, FString ContentType)
|
|
{
|
|
TUniquePtr<FHttpServerResponse> Response = MakeUnique<FHttpServerResponse>(MoveTemp(RawBytes));
|
|
Response->Code = EHttpServerResponseCodes::Ok;
|
|
|
|
TArray<FString> ContentTypeValue = { MoveTemp(ContentType) };
|
|
Response->Headers.Add(UE_HTTP_SERVER_HEADER_KEYS_CONTENT_TYPE, MoveTemp(ContentTypeValue));
|
|
return Response;
|
|
}
|
|
|
|
TUniquePtr<FHttpServerResponse> FHttpServerResponse::Create(const TArrayView<uint8>& RawBytes, FString ContentType)
|
|
{
|
|
TUniquePtr<FHttpServerResponse> Response = MakeUnique<FHttpServerResponse>();
|
|
Response->Code = EHttpServerResponseCodes::Ok;
|
|
Response->Body.Append(RawBytes.GetData(), RawBytes.Num());
|
|
|
|
TArray<FString> ContentTypeValue = { MoveTemp(ContentType) };
|
|
Response->Headers.Add(UE_HTTP_SERVER_HEADER_KEYS_CONTENT_TYPE, MoveTemp(ContentTypeValue));
|
|
return Response;
|
|
}
|
|
|
|
TUniquePtr<FHttpServerResponse> FHttpServerResponse::Ok()
|
|
{
|
|
TUniquePtr<FHttpServerResponse> Response = MakeUnique<FHttpServerResponse>();
|
|
Response->Code = EHttpServerResponseCodes::NoContent;
|
|
return Response;
|
|
}
|
|
|
|
TUniquePtr<FHttpServerResponse> FHttpServerResponse::Error(EHttpServerResponseCodes ResponseCode,
|
|
const FString& ErrorCode /*=TEXT("")*/, const FString& ErrorMessage /*=TEXT("")*/)
|
|
{
|
|
const FString ErrorCodeEscaped = ErrorCode.ReplaceCharWithEscapedChar();
|
|
const FString ErrorMessageEscaped = ErrorMessage.ReplaceCharWithEscapedChar();
|
|
const FString ResponseBody = FString::Printf(TEXT("{\"errorCode\": \"%s\", \"errorMessage\": \"%s\"}"), *ErrorCodeEscaped, *ErrorMessageEscaped);
|
|
auto Response = Create(ResponseBody, TEXT("application/json"));
|
|
Response->Code = ResponseCode;
|
|
return Response;
|
|
}
|