// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include "Containers/Array.h" #include "Containers/ArrayView.h" #include "Containers/Map.h" #include "Containers/UnrealString.h" #include "CoreMinimal.h" #include "HAL/Platform.h" #include "HttpServerConstants.h" #include "HttpServerHttpVersion.h" #include "Templates/UniquePtr.h" #include "Templates/UnrealTemplate.h" class FUtf8String; struct FHttpServerResponse final { public: /** * Constructor */ FHttpServerResponse() { } /** * Constructor * Facilitates in-place body construction * * @param InBody The r-value body data */ FHttpServerResponse(TArray&& InBody) : Body(MoveTemp(InBody)) { } /** Http protocol version */ HttpVersion::EHttpServerHttpVersion HttpVersion; /** Http Response Code */ EHttpServerResponseCodes Code; /** Http Headers */ TMap> Headers; /** Http Body Content */ TArray Body; public: /** * Creates an FHttpServerResponse from a string * * @param Text The text to serialize * @param ContentType The HTTP response content type * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Create(const FString& Text, const FString& ContentType); /** * Creates an FHttpServerResponse from a string * * @param Text The text to serialize * @param ContentType The HTTP response content type * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Create(const FUtf8String& Text, const FString& ContentType); /** * Creates an FHttpServerResponse from a string * * @param Text The text to serialize * @param ContentType The HTTP response content type * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Create(FUtf8String&& Text, const FString& ContentType); /** * Creates an FHttpServerResponse from a raw byte buffer * * @param RawBytes The byte buffer to serialize * @param ContentType The HTTP response content type * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Create(TArray&& RawBytes, FString ContentType); /** * Creates an FHttpServerResponse from a raw byte buffer * * @param RawBytes The byte buffer view to serialize * @param ContentType The HTTP response content type * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Create(const TArrayView& RawBytes, FString ContentType); /** * Creates an FHttpServerResponse 204 * * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Ok(); /** * Creates an FHttpServerResponse with the caller-supplied response and error codes * * @param ResponseCode The HTTP response code * @param ErrorCode The machine-readable error code * @param ErrorMessage The contextually descriptive error message * @return A unique pointer to an initialized response object */ HTTPSERVER_API static TUniquePtr Error(EHttpServerResponseCodes ResponseCode, const FString& ErrorCode = TEXT(""), const FString& ErrorMessage = TEXT("")); };