diff options
| author | Stefan Boberg <[email protected]> | 2021-05-20 14:22:06 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-20 14:22:06 +0200 |
| commit | 1cf2d9c75615b5fcbcfa98c85330ed1ff5c13868 (patch) | |
| tree | e56530cf1f7d7816aa4f7c308ce1720522eace80 /zencore | |
| parent | Attempt at fixing github diff view for 4-space tabs (diff) | |
| parent | Merged from master (diff) | |
| download | zen-1cf2d9c75615b5fcbcfa98c85330ed1ff5c13868.tar.xz zen-1cf2d9c75615b5fcbcfa98c85330ed1ff5c13868.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/httpserver.cpp | 48 | ||||
| -rw-r--r-- | zencore/include/zencore/httpserver.h | 15 | ||||
| -rw-r--r-- | zencore/include/zencore/string.h | 15 | ||||
| -rw-r--r-- | zencore/zencore.vcxproj | 2 |
4 files changed, 71 insertions, 9 deletions
diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index 22cba4d75..1bfe224f8 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -929,6 +929,46 @@ HttpSysServer::RemoveEndpoint(const char* UrlPath, HttpService& Service) ////////////////////////////////////////////////////////////////////////// +using namespace std::literals; + +static constinit uint32_t HashBinary = HashStringDjb2("application/octet-stream"sv); +static constinit uint32_t HashJson = HashStringDjb2("application/json"sv); +static constinit uint32_t HashText = HashStringDjb2("text/plain"sv); +static constinit uint32_t HashCompactBinary = HashStringDjb2("application/x-ue-cb"sv); +static constinit uint32_t HashCompactBinaryPackage = HashStringDjb2("application/x-ue-cbpkg"sv); + +HttpContentType +MapContentType(const std::string_view& ContentTypeString) +{ + if (!ContentTypeString.empty()) + { + const uint32_t CtHash = HashStringDjb2(ContentTypeString); + + if (CtHash == HashBinary) + { + return HttpContentType::kBinary; + } + else if (CtHash == HashCompactBinary) + { + return HttpContentType::kCbObject; + } + else if (CtHash == HashCompactBinaryPackage) + { + return HttpContentType::kCbPackage; + } + else if (CtHash == HashJson) + { + return HttpContentType::kJSON; + } + else if (CtHash == HashText) + { + return HttpContentType::kText; + } + } + + return HttpContentType::kUnknownContentType; +} + class HttpSysServerRequest : public HttpServerRequest { public: @@ -1000,10 +1040,12 @@ public: break; } - auto& clh = HttpRequestPtr->Headers.KnownHeaders[HttpHeaderContentLength]; - std::string_view cl(clh.pRawValue, clh.RawValueLength); - + const HTTP_KNOWN_HEADER& clh = HttpRequestPtr->Headers.KnownHeaders[HttpHeaderContentLength]; + std::string_view cl(clh.pRawValue, clh.RawValueLength); std::from_chars(cl.data(), cl.data() + cl.size(), m_ContentLength); + + const HTTP_KNOWN_HEADER& CtHdr = HttpRequestPtr->Headers.KnownHeaders[HttpHeaderContentType]; + m_ContentType = MapContentType({CtHdr.pRawValue, CtHdr.RawValueLength}); } ~HttpSysServerRequest() {} diff --git a/zencore/include/zencore/httpserver.h b/zencore/include/zencore/httpserver.h index d07eba339..8f762c2e4 100644 --- a/zencore/include/zencore/httpserver.h +++ b/zencore/include/zencore/httpserver.h @@ -167,7 +167,8 @@ enum class HttpContentType kText, kJSON, kCbObject, - kCbPackage + kCbPackage, + kUnknownContentType }; /** HTTP Server Request @@ -209,7 +210,8 @@ public: QueryParams GetQueryParams(); - inline HttpVerb RequestVerb() const { return m_Verb; } + inline HttpVerb RequestVerb() const { return m_Verb; } + inline HttpContentType RequestContentType() { return m_ContentType; } const char* HeaderAccept() const; const char* HeaderAcceptEncoding() const; @@ -248,6 +250,7 @@ protected: bool m_SuppressBody = false; HttpVerb m_Verb = HttpVerb::kGet; uint64_t m_ContentLength = ~0ull; + HttpContentType m_ContentType = HttpContentType::kBinary; ExtendableStringBuilder<256> m_Uri; ExtendableStringBuilder<256> m_QueryString; }; @@ -263,9 +266,9 @@ private: /** * Base class for implementing an HTTP "service" - * + * * A service exposes one or more endpoints with a certain URI prefix - * + * */ class HttpService @@ -340,10 +343,10 @@ HttpRouterRequest::GetCapture(int Index) const ////////////////////////////////////////////////////////////////////////// /** HTTP request router helper - * + * * This helper class allows a service implementer to register one or more * endpoints using pattern matching (currently using regex matching) - * + * */ class HttpRequestRouter diff --git a/zencore/include/zencore/string.h b/zencore/include/zencore/string.h index d7727ca08..684e27827 100644 --- a/zencore/include/zencore/string.h +++ b/zencore/include/zencore/string.h @@ -590,6 +590,21 @@ ParseInt(const std::string_view& Input) ////////////////////////////////////////////////////////////////////////// +constexpr uint32_t +HashStringDjb2(const std::string_view& InString) +{ + uint32_t HashValue = 5381; + + for (int c : InString) + { + HashValue = HashValue * 33 + c; + } + + return HashValue; +} + +////////////////////////////////////////////////////////////////////////// + void string_forcelink(); // internal } // namespace zen diff --git a/zencore/zencore.vcxproj b/zencore/zencore.vcxproj index c68e922c5..c9d51e0bb 100644 --- a/zencore/zencore.vcxproj +++ b/zencore/zencore.vcxproj @@ -58,10 +58,12 @@ <PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <VcpkgEnableManifest>true</VcpkgEnableManifest> <VcpkgUseStatic>true</VcpkgUseStatic> + <VcpkgAdditionalInstallOptions>--overlay-ports=$(SolutionDir)vcpkg_overlay-ports</VcpkgAdditionalInstallOptions> </PropertyGroup> <PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <VcpkgEnableManifest>true</VcpkgEnableManifest> <VcpkgUseStatic>true</VcpkgUseStatic> + <VcpkgAdditionalInstallOptions>--overlay-ports=$(SolutionDir)vcpkg_overlay-ports</VcpkgAdditionalInstallOptions> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> |