From 5a9b5be100f10cd428a1f69291b2ac34085f27dd Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Sat, 22 May 2021 17:20:27 +0200 Subject: Added ZenContentType enum to iobuffer.h - This allows us to carry the content type along with any IoBuffer instances - This replaces HttpContentType but HttpContentType remains an alias to reduce code churn - Added definition for YAML content --- zencore/httpserver.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'zencore/httpserver.cpp') diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index 1bfe224f8..2427bf9bc 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -933,6 +933,7 @@ 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 HashYaml = HashStringDjb2("text/yaml"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); @@ -960,6 +961,10 @@ MapContentType(const std::string_view& ContentTypeString) { return HttpContentType::kJSON; } + else if (CtHash == HashYaml) + { + return HttpContentType::kYAML; + } else if (CtHash == HashText) { return HttpContentType::kText; -- cgit v1.2.3 From ac7871e0b0f478da1a36da40a1a56a9f98b284df Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Sun, 23 May 2021 12:51:42 +0200 Subject: Added content type to IoBuffer payloads from http server Also added some additional logic for flagging buffer immutability --- zencore/httpserver.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'zencore/httpserver.cpp') diff --git a/zencore/httpserver.cpp b/zencore/httpserver.cpp index 2427bf9bc..bd54c90ab 100644 --- a/zencore/httpserver.cpp +++ b/zencore/httpserver.cpp @@ -1062,11 +1062,14 @@ public: HTTP_REQUEST* const HttpReq = m_HttpTx.HttpRequest(); - IoBuffer buffer(m_ContentLength); + IoBuffer PayloadBuffer(m_ContentLength); + + HttpContentType ContentType = RequestContentType(); + PayloadBuffer.SetContentType(ContentType); uint64_t BytesToRead = m_ContentLength; - uint8_t* ReadPointer = (uint8_t*)buffer.Data(); + uint8_t* ReadPointer = reinterpret_cast(PayloadBuffer.MutableData()); // First deal with any payload which has already been copied // into our request buffer @@ -1117,7 +1120,9 @@ public: ReadPointer += BytesRead; } - return buffer; + PayloadBuffer.MakeImmutable(); + + return PayloadBuffer; } virtual void WriteResponse(HttpResponse HttpResponseCode) override -- cgit v1.2.3