diff options
| author | Stefan Boberg <[email protected]> | 2021-08-20 22:15:22 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-08-20 22:15:22 +0200 |
| commit | 92f14f3e73413a70157e3dc31b083dc17951695f (patch) | |
| tree | 8e26e1197f9bc64268c635ca6c3b0ae520fdc32d /zencore/httpserver.cpp | |
| parent | Added initial sentry.io support for crash tracking etc (diff) | |
| download | zen-92f14f3e73413a70157e3dc31b083dc17951695f.tar.xz zen-92f14f3e73413a70157e3dc31b083dc17951695f.zip | |
Restructured http server code in preparation for cross platform implementation
Diffstat (limited to 'zencore/httpserver.cpp')
| -rw-r--r-- | zencore/httpserver.cpp | 113 |
1 files changed, 66 insertions, 47 deletions
diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index 72687f310..2941c287d 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -23,7 +23,9 @@ #include <doctest/doctest.h> -#pragma comment(lib, "httpapi.lib") +#if ZEN_PLATFORM_WINDOWS +# pragma comment(lib, "httpapi.lib") +#endif ////////////////////////////////////////////////////////////////////////// @@ -212,6 +214,51 @@ ReasonStringForHttpResultCode(int HttpCode) namespace zen { +using namespace std::literals; + +static const uint32_t HashBinary = HashStringDjb2("application/octet-stream"sv); +static const uint32_t HashJson = HashStringDjb2("application/json"sv); +static const uint32_t HashYaml = HashStringDjb2("text/yaml"sv); +static const uint32_t HashText = HashStringDjb2("text/plain"sv); +static const uint32_t HashCompactBinary = HashStringDjb2("application/x-ue-cb"sv); +static const 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 == HashYaml) + { + return HttpContentType::kYAML; + } + else if (CtHash == HashText) + { + return HttpContentType::kText; + } + } + + return HttpContentType::kUnknownContentType; +} + ////////////////////////////////////////////////////////////////////////// HttpServerRequest::HttpServerRequest() @@ -319,11 +366,27 @@ HttpServerRequest::GetQueryParams() return std::move(Params); } +CbObject +HttpServerRequest::ReadPayloadObject() +{ + IoBuffer Payload = ReadPayload(); + + if (Payload) + { + return LoadCompactBinaryObject(std::move(Payload)); + } + else + { + return {}; + } +} + ////////////////////////////////////////////////////////////////////////// // -// HTTP +// http.sys implementation // +#if ZEN_PLATFORM_WINDOWS class HttpSysServer; class HttpTransaction; @@ -929,51 +992,6 @@ HttpSysServer::RemoveEndpoint(const char* UrlPath, HttpService& Service) ////////////////////////////////////////////////////////////////////////// -using namespace std::literals; - -static const uint32_t HashBinary = HashStringDjb2("application/octet-stream"sv); -static const uint32_t HashJson = HashStringDjb2("application/json"sv); -static const uint32_t HashYaml = HashStringDjb2("text/yaml"sv); -static const uint32_t HashText = HashStringDjb2("text/plain"sv); -static const uint32_t HashCompactBinary = HashStringDjb2("application/x-ue-cb"sv); -static const 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 == HashYaml) - { - return HttpContentType::kYAML; - } - else if (CtHash == HashText) - { - return HttpContentType::kText; - } - } - - return HttpContentType::kUnknownContentType; -} - class HttpSysServerRequest : public HttpServerRequest { public: @@ -1323,6 +1341,7 @@ HttpTransaction::InitialRequestHandler::HandleCompletion(ULONG IoResult, ULONG_P return new HttpMessageResponseRequest(Transaction(), 500, ex.what()); } } +#endif // ZEN_PLATFORM_WINDOWS ////////////////////////////////////////////////////////////////////////// |