aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-22 17:20:27 +0200
committerStefan Boberg <[email protected]>2021-05-22 17:20:27 +0200
commit5a9b5be100f10cd428a1f69291b2ac34085f27dd (patch)
tree858f3d4f266f6c7dc1f35faf7a6a7e6db0425a10
parentAdded SharedBuffer(const IoBuffer&) (diff)
downloadzen-5a9b5be100f10cd428a1f69291b2ac34085f27dd.tar.xz
zen-5a9b5be100f10cd428a1f69291b2ac34085f27dd.zip
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
-rw-r--r--zencore/httpserver.cpp5
-rw-r--r--zencore/include/zencore/httpserver.h13
-rw-r--r--zencore/include/zencore/iobuffer.h50
3 files changed, 49 insertions, 19 deletions
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;
diff --git a/zencore/include/zencore/httpserver.h b/zencore/include/zencore/httpserver.h
index 8f762c2e4..38fdcf457 100644
--- a/zencore/include/zencore/httpserver.h
+++ b/zencore/include/zencore/httpserver.h
@@ -5,6 +5,7 @@
#include "zencore.h"
#include <zencore/enumflags.h>
+#include <zencore/iobuffer.h>
#include <zencore/refcount.h>
#include <zencore/string.h>
@@ -17,6 +18,8 @@
namespace zen {
+using HttpContentType = ZenContentType;
+
class IoBuffer;
class CbObject;
class StringBuilderBase;
@@ -161,16 +164,6 @@ enum class HttpResponse
NetworkAuthenticationRequired = 511, //!< Indicates that the client needs to authenticate to gain network access.
};
-enum class HttpContentType
-{
- kBinary,
- kText,
- kJSON,
- kCbObject,
- kCbPackage,
- kUnknownContentType
-};
-
/** HTTP Server Request
*/
class HttpServerRequest
diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h
index 7cf497527..a2ec6743d 100644
--- a/zencore/include/zencore/iobuffer.h
+++ b/zencore/include/zencore/iobuffer.h
@@ -10,6 +10,17 @@ namespace zen {
struct IoBufferExtendedCore;
+enum class ZenContentType
+{
+ kBinary, // Note that since this is zero, this will be the default value in IoBuffer
+ kText,
+ kJSON,
+ kCbObject,
+ kCbPackage,
+ kYAML,
+ kUnknownContentType
+};
+
struct IoBufferFileReference
{
void* FileHandle;
@@ -136,6 +147,14 @@ public:
}
}
+ inline void SetContentType(ZenContentType ContentType)
+ {
+ ZEN_ASSERT_SLOW((uint32_t(ContentType) & kContentTypeMask) == uint32_t(ContentType));
+ m_Flags = (m_Flags & ~(kContentTypeMask << kContentTypeShift)) | (uint32_t(ContentType) << kContentTypeShift);
+ }
+
+ inline ZenContentType GetContentType() const { return ZenContentType((m_Flags >> kContentTypeShift) & kContentTypeMask); }
+
inline uint32_t GetRefCount() const { return m_RefCount; }
protected:
@@ -145,6 +164,12 @@ protected:
size_t m_DataBytes = 0;
RefPtr<const IoBufferCore> m_OuterCore;
+ enum
+ {
+ kContentTypeShift = 24,
+ kContentTypeMask = 0xf
+ };
+
enum Flags
{
kIsOwnedByThis = 1 << 0,
@@ -153,6 +178,11 @@ protected:
kIsMaterialized = 1 << 3, // Data pointers are valid
kLowLevelAlloc = 1 << 4, // Using direct memory allocation
kIsWholeFile = 1 << 5, // References an entire file
+
+ kContentTypeBit0 = 1 << (24 + 0), // These constants
+ kContentTypeBit1 = 1 << (24 + 1), // are here mostly to
+ kContentTypeBit2 = 1 << (24 + 2), // indicate that these
+ kContentTypeBit3 = 1 << (24 + 3), // bits are reserved
};
void* AllocateBuffer(size_t InSize, size_t Alignment);
@@ -171,8 +201,8 @@ struct IoBufferExtendedCore : public IoBufferCore
enum ExtendedFlags
{
- kOwnsFile = 1 << 8,
- kOwnsMmap = 1 << 9
+ kOwnsFile = 1 << 16,
+ kOwnsMmap = 1 << 17
};
void Materialize() const;
@@ -273,13 +303,15 @@ public:
ZENCORE_API IoBuffer(EFileTag, void* FileHandle, uint64_t ChunkFileOffset, uint64_t ChunkSize);
ZENCORE_API IoBuffer(EBorrowedFileTag, void* FileHandle, uint64_t ChunkFileOffset, uint64_t ChunkSize);
- inline operator bool() const { return !m_Core->IsNull(); }
- ZENCORE_API void MakeOwned() { return m_Core->MakeOwned(); }
- inline bool IsOwned() const { return m_Core->IsOwned(); }
- inline bool IsWholeFile() const { return m_Core->IsWholeFile(); }
- const void* Data() const { return m_Core->DataPointer(); }
- const size_t Size() const { return m_Core->DataBytes(); }
- ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const;
+ inline operator bool() const { return !m_Core->IsNull(); }
+ ZENCORE_API void MakeOwned() { return m_Core->MakeOwned(); }
+ inline bool IsOwned() const { return m_Core->IsOwned(); }
+ inline bool IsWholeFile() const { return m_Core->IsWholeFile(); }
+ const void* Data() const { return m_Core->DataPointer(); }
+ const size_t Size() const { return m_Core->DataBytes(); }
+ inline void SetContentType(ZenContentType ContentType) { m_Core->SetContentType(ContentType); }
+ inline ZenContentType GetContentType() const { return m_Core->GetContentType(); }
+ ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const;
private:
RefPtr<IoBufferCore> m_Core = new IoBufferCore;