UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
HttpConnection.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
9#include "HttpServerConfig.h"
10#include "HttpServerConstants.h"
12#include "Misc/Timespan.h"
13
14class FSocket;
16class FHttpRouter;
19
21
22struct FHttpConnection final : public TSharedFromThis<FHttpConnection>
23{
24public:
25
36
42 void Tick(float DeltaTime);
43
48 {
49 return State;
50 }
51
57 void RequestDestroy(bool bGraceful);
58
63 {
64 return bKeepAlive;
65 }
66
68 {
69 return this->Socket == Other.Socket;
70 }
71
73 {
74 return GetTypeHash(Conn.Socket);
75 }
76
77private:
81 enum class EConnectionDestroyReason : uint8
82 {
84 AwaitReadTimeout,
85 BeginReadTimeout,
86 ReadTimeout,
87 WriteTimeout,
88 WriteComplete,
89 DestroyRequest
90 };
91
92private:
93
99 void ChangeState(EHttpConnectionState NewState);
100
107 void TransferState(EHttpConnectionState CurrentState, EHttpConnectionState NextState);
108
114 void BeginRead(float DeltaTime);
115
121 void ContinueRead(float DeltaTime);
122
128 void CompleteRead(const TSharedPtr<FHttpServerRequest>& Request);
129
136 void ProcessRequest(const TSharedPtr<FHttpServerRequest>& Request, const FHttpResultCallback& OnProcessingComplete);
137
145
151 void ContinueWrite(float DeltaTime);
152
156 void CompleteWrite();
157
162 void Destroy(EConnectionDestroyReason DestroyReason);
163
170 void HandleReadError(EHttpServerResponseCodes ErrorCode, const TCHAR* ErrorCodeStr);
171
177 void HandleWriteError(const TCHAR* ErrorCodeStr);
178
187
193 static const TCHAR* LexToString(EConnectionDestroyReason DestroyReason)
194 {
195 switch (DestroyReason)
196 {
197 case EConnectionDestroyReason::WriteError:
198 return TEXT("Write error");
199 case EConnectionDestroyReason::AwaitReadTimeout:
200 return TEXT("Await read timeout");
201 case EConnectionDestroyReason::BeginReadTimeout:
202 return TEXT("Begin read timeout");
203 case EConnectionDestroyReason::ReadTimeout:
204 return TEXT("Read timeout");
205 case EConnectionDestroyReason::WriteTimeout:
206 return TEXT("Write timeout");
207 case EConnectionDestroyReason::WriteComplete:
208 return TEXT("Write complete");
209 case EConnectionDestroyReason::DestroyRequest:
210 return TEXT("Destroy connection request");
211 default:
212 {
213 checkNoEntry();
214 return TEXT("Unknown");
215 }
216 }
217 }
218
219private:
220
222 FSocket* Socket;
223
226
228 const TSharedPtr<FHttpRouter> Router;
229
231 uint32 OriginPort;
232
234 uint32 ConnectionId;
235
238
241
243 bool bKeepAlive = true;
244
246 bool bGracefulDestroyRequested = false;
247
249 uint32 LastRequestNumber = 0;
250
252 static constexpr float ConnectionTimeout = 5.0f;
253
255 static constexpr float ConnectionKeepAliveTimeout = 15.0f;
256
259};
260
#define FORCEINLINE
Definition AndroidPlatform.h:140
#define checkNoEntry()
Definition AssertionMacros.h:316
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
auto Response
Definition ExternalRpcRegistry.cpp:598
EHttpConnectionState
Definition HttpConnectionTypes.h:22
EHttpServerResponseCodes
Definition HttpServerConstants.h:6
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition HttpRouter.h:13
Definition Sockets.h:19
Definition SocketSubsystem.h:58
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:1640
Definition SharedPointer.h:692
Definition UniquePtr.h:107
Definition HttpServerHttpVersion.h:7
EHttpServerHttpVersion
Definition HttpServerHttpVersion.h:9
Definition HttpConnectionRequestReadContext.h:14
Definition HttpConnectionResponseWriteContext.h:14
Definition HttpConnection.h:23
FORCEINLINE bool IsHttpKeepAliveEnabled() const
Definition HttpConnection.h:62
FORCEINLINE bool operator==(const FHttpConnection &Other) const
Definition HttpConnection.h:67
void RequestDestroy(bool bGraceful)
Definition HttpConnection.cpp:284
friend uint32 GetTypeHash(const FHttpConnection &Conn)
Definition HttpConnection.h:72
~FHttpConnection()
Definition HttpConnection.cpp:34
FORCEINLINE EHttpConnectionState GetState() const
Definition HttpConnection.h:47
Definition HttpServerConfig.h:25
Definition HttpServerRequest.h:24
Definition HttpServerResponse.h:17