34 #include "../Variable.h" 35 #include "../Exception.h" 36 #include "../HelperFunctions/Math.h" 44 #include <unordered_set> 49 int32_t _responseCode = -1;
60 enum Enum { none, request, response };
63 enum Enum { none = 0, deflate = 4, gzip = 8, br = 32 };
66 enum Enum { none = 0, gzip = 8 };
69 enum Enum { none = 0, chunked = 1, compress = 2, deflate = 4, gzip = 8, identity = 16, trailers = 32 };
72 enum Enum { none = 0, keepAlive = 1, close = 2, upgrade = 4 };
82 uint32_t contentLength = 0;
95 std::unordered_map<std::string, std::string>
cookies;
97 int32_t remotePort = 0;
98 std::map<std::string, std::string>
fields;
107 std::unordered_map<std::string, std::string>
header;
108 std::shared_ptr<std::vector<char>>
data;
137 const std::vector<char> &
getContent()
const {
return _content; }
138 uint32_t
getContentSize()
const {
return _content.empty() ? 0 : (_finished ? _content.size() - 1 : _content.size()); }
140 std::unordered_map<std::string, std::string> getParsedQueryString();
152 int32_t process(
char *buffer, int32_t bufferLength,
bool checkForChunkedXml =
false,
bool checkForChunkedJson =
false);
155 static std::string encodeURL(
const std::string &url);
156 static std::string decodeURL(
const std::string &url);
157 size_t readStream(
char *buffer,
size_t requestLength);
158 size_t readContentStream(
char *buffer,
size_t requestLength);
159 size_t readFirstContentLine(
char *buffer,
size_t requestLength);
160 std::string getMimeType(std::string extension);
161 std::string getStatusText(int32_t code);
162 std::set<std::shared_ptr<FormData>> decodeMultipartFormdata();
163 std::set<std::shared_ptr<FormData>> decodeMultipartMixed(std::string &boundary,
char *buffer,
size_t bufferSize,
char **pos);
164 static void constructHeader(uint32_t contentLength, std::string contentType, int32_t code, std::string codeDescription,
const std::vector<std::string> &additionalHeaders, std::string &header);
172 static std::string stripHeader(
const std::string &header,
const std::unordered_set<std::string> &fieldsToStrip,
const std::string &fieldsToAdd);
176 bool _contentLengthSet =
false;
177 bool _headerProcessingStarted =
false;
178 bool _dataProcessingStarted =
false;
181 std::vector<char> _rawHeader;
183 std::vector<char> _content;
184 std::vector<char> _chunk;
185 bool _chunkNewLineMissing =
false;
186 bool _finished =
false;
187 int32_t _chunkSize = -1;
188 int32_t _endChunkSizeBytes = -1;
189 std::string _partialChunkSize;
190 size_t _streamPos = 0;
191 size_t _contentStreamPos = 0;
192 static const std::map<std::string, std::string> _extMimeTypeMap;
193 static const std::map<int32_t, std::string> _statusCodeMap;
194 std::string _redirectUrl;
195 std::string _redirectQueryString;
196 int32_t _redirectStatus = -1;
197 size_t _maxHeaderSize = 102400;
198 size_t _maxContentSize = 104857600;
200 int32_t processHeader(
char **buffer, int32_t &bufferLength);
201 void processHeaderField(
char *
name, uint32_t nameSize,
char *
value, uint32_t valueSize);
202 int32_t processContent(
char *buffer, int32_t bufferLength);
203 int32_t processChunkedContent(
char *buffer, int32_t bufferLength);
204 void readChunkSize(
char **buffer, int32_t &bufferLength);
206 char *findNextString(std::string &needle,
char *buffer,
size_t bufferSize);
208 int32_t strnaicmp(
char const *a,
char const *b, uint32_t size);
int32_t getRedirectStatus()
Definition: Http.h:122
void setMaxHeaderSize(size_t value)
Definition: Http.h:125
void setRedirectQueryString(std::string value)
Definition: Http.h:121
size_t getMaxHeaderSize()
Definition: Http.h:124
Enum
Definition: Http.h:63
std::string getRedirectUrl()
Definition: Http.h:118
Enum
Definition: Http.h:75
Type::Enum getType()
Definition: Http.h:115
Definition: BaseLib.cpp:34
bool headerIsFinished()
Definition: Http.h:116
Enum
Definition: Http.h:66
bool isFinished()
Definition: Http.h:117
void setRedirectStatus(int32_t value)
Definition: Http.h:123
PVariable value
Definition: UiElements.h:217
int32_t responseCode() const
Definition: Http.h:54
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
Enum
Definition: Http.h:72
bool dataProcessingStarted()
Definition: Http.h:154
uint32_t getContentSize() const
Definition: Http.h:138
void setRedirectUrl(std::string value)
Definition: Http.h:119
bool headerProcessingStarted()
Definition: Http.h:153
const std::vector< char > & getContent() const
Definition: Http.h:137
HttpException(std::string message, int32_t responseCode)
Definition: Http.h:52
std::string getRedirectQueryString()
Definition: Http.h:120
Header & getHeader()
Definition: Http.h:139
Enum
Definition: Http.h:60
std::string name
Definition: UiElements.h:216
Base class for all exceptions defined in Homegear.
Definition: Exception.h:41
HttpException(std::string message)
Definition: Http.h:51
void setMaxContentSize(size_t value)
Definition: Http.h:127
const std::vector< char > & getRawHeader() const
Definition: Http.h:136
size_t getMaxContentSize()
Definition: Http.h:126
Enum
Definition: Http.h:69