diff options
| author | Stefan Boberg <[email protected]> | 2021-09-15 21:39:53 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-15 21:39:53 +0200 |
| commit | 2f28b9bee4da0ddebe0f6de9419e3b3f80ca0911 (patch) | |
| tree | 2e377c2740e5cda528bda2bbff49cebbfb2c5962 | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| download | zen-2f28b9bee4da0ddebe0f6de9419e3b3f80ca0911.tar.xz zen-2f28b9bee4da0ddebe0f6de9419e3b3f80ca0911.zip | |
Added session id generation and code to include it in HttpClient HTTP requests
| -rw-r--r-- | zencore/include/zencore/session.h | 11 | ||||
| -rw-r--r-- | zencore/session.cpp | 21 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj | 5 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj.filters | 5 | ||||
| -rw-r--r-- | zenhttp/httpclient.cpp | 10 | ||||
| -rw-r--r-- | zenhttp/include/zenhttp/httpclient.h | 2 |
6 files changed, 50 insertions, 4 deletions
diff --git a/zencore/include/zencore/session.h b/zencore/include/zencore/session.h new file mode 100644 index 000000000..e66794704 --- /dev/null +++ b/zencore/include/zencore/session.h @@ -0,0 +1,11 @@ +#pragma once + +#include <zencore/zencore.h> + +namespace zen { + +struct Oid; + +ZENCORE_API Oid GetSessionId(); + +} diff --git a/zencore/session.cpp b/zencore/session.cpp new file mode 100644 index 000000000..195a9d97c --- /dev/null +++ b/zencore/session.cpp @@ -0,0 +1,21 @@ +#include "zencore/session.h" + +#include <zencore/uid.h> + +#include <mutex> + +namespace zen { + +static Oid GlobalSessionId; +static std::once_flag SessionInitFlag; + +Oid GetSessionId() +{ + std::call_once(SessionInitFlag, [&] { + GlobalSessionId.Generate(); + }); + + return GlobalSessionId; +} + +}
\ No newline at end of file diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj index 4f1e63670..150c42cd6 100644 --- a/zencore/zencore.vcxproj +++ b/zencore/zencore.vcxproj @@ -132,6 +132,7 @@ <ClInclude Include="include\zencore\prewindows.h" /> <ClInclude Include="include\zencore\refcount.h" /> <ClInclude Include="include\zencore\scopeguard.h" /> + <ClInclude Include="include\zencore\session.h" /> <ClInclude Include="include\zencore\sha1.h" /> <ClInclude Include="include\zencore\iobuffer.h" /> <ClInclude Include="include\zencore\sharedbuffer.h" /> @@ -166,6 +167,7 @@ <ClCompile Include="md5.cpp" /> <ClCompile Include="memory.cpp" /> <ClCompile Include="refcount.cpp" /> + <ClCompile Include="session.cpp" /> <ClCompile Include="sha1.cpp"> <Optimization Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">MaxSpeed</Optimization> <InlineFunctionExpansion Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AnySuitable</InlineFunctionExpansion> @@ -189,6 +191,9 @@ <ClCompile Include="xxhash.cpp" /> <ClCompile Include="zencore.cpp" /> </ItemGroup> + <ItemGroup> + <None Include="xmake.lua" /> + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> diff --git a/zencore/zencore.vcxproj.filters b/zencore/zencore.vcxproj.filters index de3d915b8..ea0f8a912 100644 --- a/zencore/zencore.vcxproj.filters +++ b/zencore/zencore.vcxproj.filters @@ -41,6 +41,7 @@ <ClInclude Include="include\zencore\prewindows.h" /> <ClInclude Include="include\zencore\postwindows.h" /> <ClInclude Include="include\zencore\logging.h" /> + <ClInclude Include="include\zencore\session.h" /> </ItemGroup> <ItemGroup> <ClCompile Include="snapshot_manifest.cpp" /> @@ -72,10 +73,14 @@ <ClCompile Include="crc32.cpp" /> <ClCompile Include="logging.cpp" /> <ClCompile Include="intmath.cpp" /> + <ClCompile Include="session.cpp" /> </ItemGroup> <ItemGroup> <Filter Include="CAS"> <UniqueIdentifier>{af5266fa-37a5-494c-9116-b15a3e6edd29}</UniqueIdentifier> </Filter> </ItemGroup> + <ItemGroup> + <None Include="xmake.lua" /> + </ItemGroup> </Project>
\ No newline at end of file diff --git a/zenhttp/httpclient.cpp b/zenhttp/httpclient.cpp index b7df12026..78ecef2c0 100644 --- a/zenhttp/httpclient.cpp +++ b/zenhttp/httpclient.cpp @@ -7,6 +7,7 @@ #include <zencore/compactbinarypackage.h> #include <zencore/iobuffer.h> #include <zencore/logging.h> +#include <zencore/session.h> #include <zencore/sharedbuffer.h> #include <zencore/stream.h> @@ -30,6 +31,9 @@ FromCprResponse(cpr::Response& InResponse) HttpClient::HttpClient(std::string_view BaseUri) : m_BaseUri(BaseUri) { + StringBuilder<32> SessionId; + GetSessionId().ToString(SessionId); + m_SessionId = SessionId; } HttpClient::~HttpClient() @@ -68,8 +72,7 @@ HttpClient::TransactPackage(std::string_view Url, CbPackage Package) BinaryWriter MemWriter(MemOut); Writer.Save(MemWriter); - Sess.SetHeader( - {{"Content-Type", "application/x-ue-offer"}, {"UE-Session", "123456789012345678901234"}, {"UE-Request", RequestIdString}}); + Sess.SetHeader({{"Content-Type", "application/x-ue-offer"}, {"UE-Session", m_SessionId}, {"UE-Request", RequestIdString}}); Sess.SetBody(cpr::Body{(const char*)MemOut.Data(), MemOut.Size()}); cpr::Response FilterResponse = Sess.Post(); @@ -111,8 +114,7 @@ HttpClient::TransactPackage(std::string_view Url, CbPackage Package) CompositeBuffer Message = FormatPackageMessageBuffer(SendPackage); SharedBuffer FlatMessage = Message.Flatten(); - Sess.SetHeader( - {{"Content-Type", "application/x-ue-cbpkg"}, {"UE-Session", "123456789012345678901234"}, {"UE-Request", RequestIdString}}); + Sess.SetHeader({{"Content-Type", "application/x-ue-cbpkg"}, {"UE-Session", m_SessionId}, {"UE-Request", RequestIdString}}); Sess.SetBody(cpr::Body{(const char*)FlatMessage.GetData(), FlatMessage.GetSize()}); cpr::Response FilterResponse = Sess.Post(); diff --git a/zenhttp/include/zenhttp/httpclient.h b/zenhttp/include/zenhttp/httpclient.h index 8975f6fe1..c3bdf0506 100644 --- a/zenhttp/include/zenhttp/httpclient.h +++ b/zenhttp/include/zenhttp/httpclient.h @@ -5,6 +5,7 @@ #include "zenhttp.h" #include <zencore/iobuffer.h> +#include <zencore/uid.h> #include <zenhttp/httpcommon.h> #include <zencore/windows.h> @@ -41,6 +42,7 @@ public: private: std::string m_BaseUri; + std::string m_SessionId; }; } // namespace zen |