diff options
| author | Stefan Boberg <[email protected]> | 2021-05-23 12:51:42 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-23 12:51:42 +0200 |
| commit | ac7871e0b0f478da1a36da40a1a56a9f98b284df (patch) | |
| tree | 813025a218a45b6e44b36fb4a4d44dbf0504d3b6 /zencore | |
| parent | Added static_assert to ensure content type fits in allocated space (diff) | |
| download | zen-ac7871e0b0f478da1a36da40a1a56a9f98b284df.tar.xz zen-ac7871e0b0f478da1a36da40a1a56a9f98b284df.zip | |
Added content type to IoBuffer payloads from http server
Also added some additional logic for flagging buffer immutability
Diffstat (limited to 'zencore')
| -rw-r--r-- | zencore/httpserver.cpp | 11 | ||||
| -rw-r--r-- | zencore/include/zencore/iobuffer.h | 20 | ||||
| -rw-r--r-- | zencore/iobuffer.cpp | 2 |
3 files changed, 21 insertions, 12 deletions
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<uint8_t*>(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 diff --git a/zencore/include/zencore/iobuffer.h b/zencore/include/zencore/iobuffer.h index a515f7af8..861ace575 100644 --- a/zencore/include/zencore/iobuffer.h +++ b/zencore/include/zencore/iobuffer.h @@ -305,15 +305,17 @@ 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(); } - inline void SetContentType(ZenContentType ContentType) { m_Core->SetContentType(ContentType); } - inline ZenContentType GetContentType() const { return m_Core->GetContentType(); } - ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const; + inline operator bool() const { return !m_Core->IsNull(); } + inline void MakeOwned() { return m_Core->MakeOwned(); } + [[nodiscard]] inline bool IsOwned() const { return m_Core->IsOwned(); } + [[nodiscard]] inline bool IsWholeFile() const { return m_Core->IsWholeFile(); } + [[nodiscard]] void* MutableData() const { return m_Core->MutableDataPointer(); } + void MakeImmutable() { m_Core->SetIsImmutable(true); } + [[nodiscard]] const void* Data() const { return m_Core->DataPointer(); } + [[nodiscard]] const size_t Size() const { return m_Core->DataBytes(); } + inline void SetContentType(ZenContentType ContentType) { m_Core->SetContentType(ContentType); } + [[nodiscard]] inline ZenContentType GetContentType() const { return m_Core->GetContentType(); } + [[nodiscard]] ZENCORE_API bool GetFileReference(IoBufferFileReference& OutRef) const; private: RefPtr<IoBufferCore> m_Core = new IoBufferCore; diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index d32a30358..732d4d603 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -237,10 +237,12 @@ IoBufferExtendedCore::GetFileReference(IoBufferFileReference& OutRef) const IoBuffer::IoBuffer(size_t InSize) : m_Core(new IoBufferCore(InSize)) { + m_Core->SetIsImmutable(false); } IoBuffer::IoBuffer(size_t InSize, uint64_t InAlignment) : m_Core(new IoBufferCore(InSize, InAlignment)) { + m_Core->SetIsImmutable(false); } IoBuffer::IoBuffer(const IoBuffer& OuterBuffer, size_t Offset, size_t Size) |