EHS
Loading...
Searching...
No Matches
Request.h
Go to the documentation of this file.
1#pragma once
2
3#include "ehs/EHS.h"
4#include "ehs/Vector.h"
5#include "ehs/Str.h"
6#include "ehs/json/Json.h"
7#include "Socket.h"
8
9namespace ehs
10{
11 enum class Verb
12 {
17 };
18
19 class EHS_LIB_IO Request
20 {
21 private:
22 Verb verb;
23 Str_8 rsrc;
24 Vector<Str_8> queries;
25 Vector<Str_8> header;
26 ContentType cType;
27 Str_8 body;
28
29 public:
31 Request();
32
36 Request(const Verb verb, const Str_8& rsrc);
37
41 Request(const char* data, const UInt_64 size);
42
45 Request(const Str_8& data);
46
49 Request(const Request& req) = default;
50
54 Request& operator=(const Request& req);
55
58 Verb GetVerb() const;
59
62 void SetContentType(const ContentType cType);
63
67
70 void SetResource(const Str_8& rsrc);
71
74 Str_8 GetResource() const;
75
79 void AddQuery(const Str_8& var, const Str_8& value);
80
84 Str_8 GetQuery(const Str_8& var);
85
89
93 void BasicAuth(const Str_8& id, const Str_8& secret);
94
97 void BearerAuth(const Str_8& token);
98
102 void BearerAuth(const Str_8& token, const Str_8& clientId);
103
106 void BotAuth(const Str_8& token);
107
111 void AddToHeader(const Str_8& var, const Str_8& value);
112
116 Str_8 GetHeader(const Str_8& var) const;
117
120 Vector<Str_8> GetHeader() const;
121
125 void AddToBody(const Str_8& var, const Str_8& value);
126
129 void AddToBody(const Str_8& data);
130
133 void SetBody(const Str_8& body);
134
138 Str_8 GetVar(const Str_8& var) const;
139
142 Str_8 GetBody() const;
143
146 Json GetJson() const;
147
150 Str_8 FormResult() const;
151
152 bool IsValid() const;
153
154 private:
155 static Str_8 VerbToStr(const Verb verb);
156
157 static Str_8 ContentTypeToStr(const ContentType cType);
158
159 static ContentType StrToContentType(const Str_8& value);
160
161 void ReadData(const Str_8& data);
162
163 };
164}
Definition Json.h:16
void BasicAuth(const Str_8 &id, const Str_8 &secret)
Definition Request.cpp:94
Str_8 GetBody() const
Definition Request.cpp:188
void AddQuery(const Str_8 &var, const Str_8 &value)
Definition Request.cpp:71
Verb GetVerb() const
Definition Request.cpp:43
void SetContentType(const ContentType cType)
Definition Request.cpp:48
void AddToHeader(const Str_8 &var, const Str_8 &value)
Definition Request.cpp:115
Json GetJson() const
Definition Request.cpp:193
void AddToBody(const Str_8 &var, const Str_8 &value)
Definition Request.cpp:138
Str_8 GetVar(const Str_8 &var) const
Definition Request.cpp:170
ContentType GetContentType() const
Definition Request.cpp:56
Vector< Str_8 > GetQueries() const
Definition Request.cpp:89
Request & operator=(const Request &req)
Definition Request.cpp:28
void SetResource(const Str_8 &rsrc)
Definition Request.cpp:61
void SetBody(const Str_8 &body)
Definition Request.cpp:165
Str_8 GetQuery(const Str_8 &var)
Definition Request.cpp:76
void BearerAuth(const Str_8 &token)
Definition Request.cpp:99
bool IsValid() const
Definition Request.cpp:225
Str_8 GetResource() const
Definition Request.cpp:66
Str_8 GetHeader(const Str_8 &var) const
Definition Request.cpp:120
Str_8 FormResult() const
Definition Request.cpp:198
Request(const Request &req)=default
Request()
Default member initialization.
Definition Request.cpp:6
void BotAuth(const Str_8 &token)
Definition Request.cpp:110
Definition Vector.h:18
Definition Anchor.h:6
ContentType
Definition Socket.h:35
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1902
Verb
Definition Request.h:12
@ DEL
Definition Request.h:16
@ PUT
Definition Request.h:15
@ GET
Definition Request.h:14
@ POST
Definition Request.h:13