SpiecsEngine
 
Loading...
Searching...
No Matches
HttpRequest.h
Go to the documentation of this file.
1/**
2* @file HttpRequest.h.
3* @brief The HttpRequest 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 Http Request body.
16 */
18 {
19 public:
20
21 enum class Method
22 {
23 Invalid = 0,
24 Get = 1,
25 Post = 2,
26 Head = 3,
27 Put = 4,
28 Delete = 5
29 };
30
31 enum class Version
32 {
33 UnKonwn = 0,
34 HTTP10 = 1,
35 HTTP11 = 2
36 };
37
38 public:
39
40 /**
41 * @brief Constructor Function.
42 * @param[in] version Http Version.
43 */
47 , m_Path("")
48 {}
49
50 /**
51 * @brief Destructor Function.
52 */
53 virtual ~HttpRequest() = default;
54
55 /**
56 * @brief Set Http path.
57 * @param[in] path Http Path.
58 */
59 void SetPath(const std::string& path);
60
61 /**
62 * @brief Get Http path.
63 * @return Returns Http Path.
64 */
65 const std::string& GetPath() { return m_Path; }
66
67 /**
68 * @brief Set Http Method.
69 * @param[in] method Http Method.
70 */
71 void SetMethod(Method method);
72
73 /**
74 * @brief Get Http Method.
75 * @return Returns Http Method.
76 */
77 const Method GetMethod() const { return m_Method; }
78
79 /**
80 * @brief Set Http Version.
81 * @param[in] version Http Version.
82 */
83 void SetVersion(Version version);
84
85 /**
86 * @brief Get Http Version.
87 * @return Returns Http Version.
88 */
89 const Version GetVersion() const { return m_Version; }
90
91 /**
92 * @brief Add a Parameter to this HttpRequest.
93 * @param[in] name Parameter name.
94 * @param[in] value Parameter value.
95 */
96 void AddParameter(const std::string& name, const std::string& value);
97
98 /**
99 * @brief Add a Header to this HttpRequest.
100 * @param[in] name Header name.
101 * @param[in] value Header value.
102 */
103 void AddHeader(const std::string& name, const std::string& value);
104
105 /**
106 * @brief Get a Header from this HttpRequest.
107 * @param[in] name Header name.
108 * return Returns Header name.
109 */
110 std::string GetHeader(const std::string& name) const;
111
112 /**
113 * @brief Swap with another HttpRequest.
114 * @param[in] rhs another HttpRequest.
115 */
116 void Swap(HttpRequest& rhs);
117
118 private:
119
120 /**
121 * @brief Http Method.
122 */
124
125 /**
126 * @brief Http Version.
127 */
129
130 /**
131 * @brief Http Path.
132 */
133 std::string m_Path;
134
135 /**
136 * @brief Http Parameters.
137 */
139
140 /**
141 * @brief Http Headers.
142 */
144
145 };
146
147}
148
149}
#define SPICES_PROFILE_ZONE
Wrapper of readwrite buffer.
Definition Buffer.h:19
virtual ~HttpContext()=default
Destructor Function.
RequestParseState m_RequestParseState
RequestParseState.
Definition HttpContext.h:69
const HttpRequest & GetRequest()
Get HttpRequest. @reutrn Returns HttpRequest.
Definition HttpContext.h:48
HttpRequest m_HttpRequest
HttpRequest.
Definition HttpContext.h:74
bool GotAll()
Determine if RequestParseState is GotAll.
Definition HttpContext.h:56
bool ProcessRequestLine(const char *begin, const char *end)
HttpContext()
Constructor Function.
Definition HttpContext.h:37
bool ParseRequest(Buffer *buf)
Version m_Version
Http Version.
std::unordered_map< std::string, std::string > m_Headers
Http Headers.
void Swap(HttpRequest &rhs)
Swap with another HttpRequest.
void AddHeader(const std::string &name, const std::string &value)
Add a Header to this HttpRequest.
void SetMethod(Method method)
Set Http Method.
const std::string & GetPath()
Get Http path.
Definition HttpRequest.h:65
void AddParameter(const std::string &name, const std::string &value)
Add a Parameter to this HttpRequest.
const Version GetVersion() const
Get Http Version.
Definition HttpRequest.h:89
const Method GetMethod() const
Get Http Method.
Definition HttpRequest.h:77
std::string m_Path
Http Path.
std::unordered_map< std::string, std::string > m_Parameters
Http Parameters.
Method m_Method
Http Method.
std::string GetHeader(const std::string &name) const
Get a Header from this HttpRequest.
void SetVersion(Version version)
Set Http Version.
void SetPath(const std::string &path)
Set Http path.
HttpRequest()
Constructor Function.
Definition HttpRequest.h:44
virtual ~HttpRequest()=default
Destructor Function.
Http Request body.
Definition HttpRequest.h:18