DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
HttpContext.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "Common.h"
7#include "System/Object.h"
8#include "System/String.h"
13
14namespace DotNetDupe {
15 namespace WebAppCore {
16 namespace Http {
17
25 class HttpRequest : public virtual DotNetDupe::System::Object {
26 public:
28 HttpRequest() = default;
29
31 ~HttpRequest() override = default;
32
35 DotNetDupe::System::String GetMethod() const { return m_sMethod; }
36
39 void SetMethod(const DotNetDupe::System::String& method) { m_sMethod = method; }
40
43 DotNetDupe::System::String GetPath() const { return m_sPath; }
44
47 void SetPath(const DotNetDupe::System::String& path) { m_sPath = path; }
48
51 DotNetDupe::System::String GetBody() const { return m_sBody; }
52
55 void SetBody(const DotNetDupe::System::String& body) { m_sBody = body; }
56
60
64
68
72
76
80
81 private:
88 };
89
98 public:
100 HttpResponse() : m_nStatusCode(200), m_sContentType("text/plain"), m_bHeadersSent(false), m_bChunked(false) {}
101
103 ~HttpResponse() override = default;
104
107 int GetStatusCode() const { return m_nStatusCode; }
108
111 void SetStatusCode(int code) { m_nStatusCode = code; }
112
115 void SetStatusCode(DotNetDupe::System::Net::HttpStatusCode code) { m_nStatusCode = static_cast<int>(code); }
116
120
123 DotNetDupe::System::String GetContentType() const { return m_sContentType; }
124
127 void SetContentType(const DotNetDupe::System::String& type) { m_sContentType = type; }
128
131 DotNetDupe::System::String GetBody() const { return m_sBody; }
132
135 void SetBody(const DotNetDupe::System::String& body) { m_sBody = body; }
136
139 void Write(const DotNetDupe::System::String& text) { m_sBody = m_sBody + text; }
140
144
148
152
155 bool IsHeadersSent() const { return m_bHeadersSent; }
156
159 bool IsChunked() const { return m_bChunked; }
160
163 void SetChunked(bool bChunked) { m_bChunked = bChunked; }
164
167
171
173 DOTNETDUPE_API void Flush();
174
175 private:
176 int m_nStatusCode;
177 DotNetDupe::System::String m_sContentType;
181 bool m_bHeadersSent;
182 bool m_bChunked;
183 };
184
216
217 }
218 }
219}
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
Defines HTTP status codes defined for HTTP/1.1 and HTTP/2.
Provides the underlying stream of data for network access.
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.
Represents a collection of keys and values.
Definition Dictionary.h:66
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
DotNetDupe::System::SmartPointer< HttpRequest > GetRequest() const
Gets the HttpRequest representation for this execution context.
~HttpContext() override=default
Virtual destructor.
HttpContext()
Default constructor instantiating paired HttpRequest and HttpResponse objects.
DotNetDupe::System::SmartPointer< HttpResponse > GetResponse() const
Gets the HttpResponse representation for this execution context.
void SetPath(const DotNetDupe::System::String &path)
Sets the request URI path.
Definition HttpContext.h:47
DotNetDupe::System::String GetBody() const
Gets the raw HTTP request body string.
Definition HttpContext.h:51
DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetRouteValues()
Gets the mutable dictionary of matched route parameter values.
Definition HttpContext.h:75
const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetQuery() const
Gets the read-only dictionary of decoded URL query parameters.
Definition HttpContext.h:71
DotNetDupe::System::String GetMethod() const
Gets the HTTP request method verb (e.g., "GET", "POST").
Definition HttpContext.h:35
void SetMethod(const DotNetDupe::System::String &method)
Sets the HTTP request method verb.
Definition HttpContext.h:39
DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetQuery()
Gets the mutable dictionary of decoded URL query parameters.
Definition HttpContext.h:67
const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetRouteValues() const
Gets the read-only dictionary of matched route parameter values.
Definition HttpContext.h:79
DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetHeaders()
Gets the mutable dictionary of HTTP request headers.
Definition HttpContext.h:59
HttpRequest()=default
Default constructor.
const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetHeaders() const
Gets the read-only dictionary of HTTP request headers.
Definition HttpContext.h:63
DotNetDupe::System::String GetPath() const
Gets the request URI path.
Definition HttpContext.h:43
~HttpRequest() override=default
Virtual destructor.
void SetBody(const DotNetDupe::System::String &body)
Sets the raw HTTP request body string.
Definition HttpContext.h:55
void SetStatusCode(int code)
Sets the integer HTTP response status code.
void BindStream(DotNetDupe::System::SmartPointer< DotNetDupe::System::Net::Sockets::NetworkStream > pStream)
Binds the underlying network stream to this response for direct writing or streaming.
HttpResponse()
Default constructor initializing status code 200 OK and text/plain content type.
void SetStatusCode(DotNetDupe::System::Net::HttpStatusCode code)
Sets the HTTP response status code via HttpStatusCode enum.
void Write(const DotNetDupe::System::String &text)
Appends text to the response body buffer.
DotNetDupe::System::String GetContentType() const
Gets the Content-Type header string.
void SetChunked(bool bChunked)
Sets whether chunked transfer-encoding should be used.
int GetStatusCode() const
Gets the integer HTTP response status code.
void SetContentType(const DotNetDupe::System::String &type)
Sets the Content-Type header string.
void FlushHeaders()
Serializes and transmits the HTTP status line and response headers to the network stream.
DotNetDupe::System::String GetBody() const
Gets the accumulated response body string.
bool IsHeadersSent() const
Indicates whether the HTTP response status line and headers have already been transmitted.
const DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetHeaders() const
Gets the read-only dictionary of HTTP response headers.
DotNetDupe::System::Collections::Generic::Dictionary< DotNetDupe::System::String, DotNetDupe::System::String > & GetHeaders()
Gets the mutable dictionary of HTTP response headers.
void SetBody(const DotNetDupe::System::String &body)
Sets the response body content.
bool IsChunked() const
Indicates whether chunked transfer-encoding is enabled for this response.
void WriteChunk(const DotNetDupe::System::String &data)
Writes a chunk of data using HTTP/1.1 chunked transfer encoding.
~HttpResponse() override=default
Virtual destructor.
void Flush()
Flushes any remaining response body or terminal chunk marker to the client stream.
DotNetDupe::System::Net::HttpStatusCode GetStatusCodeEnum() const
Gets the HTTP response status code as a strongly-typed HttpStatusCode enum.
HttpStatusCode
Contains the values of status codes defined for HTTP in RFC 9110 and RFC 7231.