DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
HttpContent.h
Go to the documentation of this file.
1
3
4#pragma once
5#include "Common.h"
6#include "System/Object.h"
7#include "System/String.h"
8#include "System/Array.h"
10#include "System/IO/Stream.h"
12
13namespace DotNetDupe {
14 namespace System {
15 namespace Net {
16 namespace Http {
17
23 class HttpContent : public Object {
24 public:
26 DOTNETDUPE_API virtual ~HttpContent() = default;
27
31
35
39
43 DOTNETDUPE_API virtual void CopyTo(const SmartPointer<IO::Stream>& stream);
44
47 DOTNETDUPE_API virtual long GetLength() const;
48
52
56
57 protected:
60
61 private:
63 };
64
67
70 class StringContent : public HttpContent {
71 public:
74 DOTNETDUPE_API explicit StringContent(const String& content);
75
79 DOTNETDUPE_API StringContent(const String& content, const String& mediaType);
80
84
88
92
95 DOTNETDUPE_API void CopyTo(const SmartPointer<IO::Stream>& stream) override;
96
99 DOTNETDUPE_API long GetLength() const override;
100
101 private:
102 String m_sContent;
103 };
104
108 public:
111 DOTNETDUPE_API explicit ByteArrayContent(const Array<char>& content);
112
117 DOTNETDUPE_API ByteArrayContent(const Array<char>& content, int offset, int count);
118
122
126
130
133 DOTNETDUPE_API void CopyTo(const SmartPointer<IO::Stream>& stream) override;
134
137 DOTNETDUPE_API long GetLength() const override;
138
139 private:
140 Array<char> m_arrContent;
141 int m_iOffset;
142 int m_iCount;
143 };
144
147 class StreamContent : public HttpContent {
148 public:
152
156
160
164
167 DOTNETDUPE_API void CopyTo(const SmartPointer<IO::Stream>& stream) override;
168
171 DOTNETDUPE_API long GetLength() const override;
172
173 private:
174 SmartPointer<IO::Stream> m_pStream;
175 };
176
177 }
178 }
179 }
180}
Provides methods for creating, manipulating, searching, and sorting arrays.
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
High-performance UTF-8 / UTF-16 string manipulation class mirroring .NET System.String.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition Array.h:29
Represents a collection of keys and values.
Definition Dictionary.h:66
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Copies the byte buffer into the target stream.
long GetLength() const override
Returns the byte count of the buffer slice.
String ReadAsString() override
Reads the byte buffer decoded as a string.
SmartPointer< IO::Stream > ReadAsStream() override
Reads the content as a MemoryStream.
ByteArrayContent(const Array< char > &content)
Initializes a new instance of ByteArrayContent with full byte buffer.
Array< char > ReadAsByteArray() override
Reads the content byte buffer.
virtual ~HttpContent()=default
Virtual destructor for polymorphic cleanup.
virtual SmartPointer< IO::Stream > ReadAsStream()=0
Serializes the HTTP content and returns a stream that represents the content.
virtual void CopyTo(const SmartPointer< IO::Stream > &stream)
Serializes the HTTP content to a stream.
virtual long GetLength() const
Gets the length in bytes of the HHTP content, or -1 if indeterminate.
HttpContent()=default
Protected default constructor for derived content types.
virtual Array< char > ReadAsByteArray()=0
Serializes the HTTP content to a byte array.
const Collections::Generic::Dictionary< String, String > & GetHeaders() const
Gets the HTTP content headers as read-only.
Definition HttpContent.h:55
Collections::Generic::Dictionary< String, String > & GetHeaders()
Gets the HTTP content headers defined in RFC 9110.
Definition HttpContent.h:51
virtual String ReadAsString()=0
Serializes the HTTP content to a string as an operation.
StreamContent(const SmartPointer< IO::Stream > &stream)
Initializes a new instance of StreamContent wrapping an existing Stream.
SmartPointer< IO::Stream > ReadAsStream() override
Returns the underlying stream.
Array< char > ReadAsByteArray() override
Reads the remaining bytes in the stream into a byte array.
long GetLength() const override
Gets the length of the underlying stream if seekable, or -1.
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Copies the underlying stream into the destination stream.
String ReadAsString() override
Reads the remaining bytes in the stream into a string.
Array< char > ReadAsByteArray() override
Reads the content payload as a byte array.
SmartPointer< IO::Stream > ReadAsStream() override
Reads the content payload as a readable MemoryStream.
String ReadAsString() override
Reads the content payload as a string.
void CopyTo(const SmartPointer< IO::Stream > &stream) override
Writes the content string directly to the destination stream.
long GetLength() const override
Gets the length in bytes of the UTF-8 content string.
StringContent(const String &content)
Creates a new instance of StringContent with text/plain default media type.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
SmartPointer< HttpContent > HttpContentPtr
Type alias for reference-counted SmartPointer to HttpContent.
Definition HttpContent.h:66