SpiecsEngine
 
Loading...
Searching...
No Matches
HttpResponse.h
Go to the documentation of this file.
1/**
2* @file HttpResponse.h.
3* @brief The HttpResponse Class Definitions.
4* @author Spices & Muduo.
5*/
6
7#pragma once
8#include "Core/Core.h"
9
10namespace Spices {
11
12namespace Net {
13
14 /**
15 * @brief Forward Declare.
16 */
17 class Buffer;
18
19 /**
20 * @brief Http Response.
21 */
23 {
24 public:
25
27 {
29 Ok = 200,
32 NotFound = 404,
33 };
34
35 public:
36
37 /**
38 * @brief Constructor Function.
39 * @param[in] close Is should be close.
40 */
41 explicit HttpResponse(bool close)
43 , m_CloseConnection(close)
44 {}
45
46 /**
47 * @brief Destructor Function.
48 */
49 virtual ~HttpResponse() = default;
50
51 /**
52 * @brief Set StatusCode.
53 * @param[in] code StatusCode.
54 */
55 void SetStatusCode(StatusCode code);
56
57 /**
58 * @brief Set StatusMessage.
59 * @param[in] message StatusMessage.
60 */
61 void SetStatusMessage(const std::string& message);
62
63 /**
64 * @brief Set CloseConnection.
65 * @param[in] on CloseConnection.
66 */
67 void SetCloseConnection(bool on);
68
69 /**
70 * @brief Get CloseConnection.
71 * @return Returns CloseConnection.
72 */
73 bool CloseConnection() const;
74
75 /**
76 * @brief Set ContentType.
77 * @param[in] contentType ContentType.
78 */
79 void SetContentType(const std::string& contentType);
80
81 /**
82 * @brief Add a header.
83 * @param[in] name header name.
84 * @param[in] value header value.
85 */
86 void AddHeader(const std::string& name, const std::string& value);
87
88 /**
89 * @brief Set body.
90 * @param[in] body .
91 */
92 void SetBody(const std::string& body);
93
94 /**
95 * @brief Append this response to Buffer.
96 * @param[in] output output buffer.
97 */
98 void AppendToBuffer(Buffer* output);
99
100 private:
101
102 /**
103 * @brief This response header.
104 */
106
107 /**
108 * @brief StatusCode.
109 */
111
112 /**
113 * @brief StatusMessage.
114 */
115 std::string m_StatusMessage;
116
117 /**
118 * @brief CloseConnection.
119 */
121
122 /**
123 * @brief Body.
124 */
125 std::string m_Body;
126 };
127
128}
129
130}
#define SPICES_PROFILE_ZONE
void Append(const std::string &msg)
Append Message to this buffer.
Definition Buffer.cpp:41
Wrapper of readwrite buffer.
Definition Buffer.h:19
void SetCloseConnection(bool on)
Set CloseConnection.
HttpResponse(bool close)
Constructor Function.
void SetContentType(const std::string &contentType)
Set ContentType.
std::string m_StatusMessage
StatusMessage.
StatusCode m_StatusCode
StatusCode.
bool m_CloseConnection
CloseConnection.
void SetBody(const std::string &body)
Set body.
void SetStatusCode(StatusCode code)
Set StatusCode.
void SetStatusMessage(const std::string &message)
Set StatusMessage.
void AddHeader(const std::string &name, const std::string &value)
Add a header.
std::string m_Body
Body.
void AppendToBuffer(Buffer *output)
Append this response to Buffer.
virtual ~HttpResponse()=default
Destructor Function.
bool CloseConnection() const
Get CloseConnection.
std::unordered_map< std::string, std::string > m_Header
This response header.