forked from awwit/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataVariantFormUrlencoded.cpp
More file actions
62 lines (50 loc) · 1.63 KB
/
DataVariantFormUrlencoded.cpp
File metadata and controls
62 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "DataVariantFormUrlencoded.h"
#include "Utils.h"
namespace HttpServer
{
DataVariantFormUrlencoded::DataVariantFormUrlencoded()
{
data_variant_name = "application/x-www-form-urlencoded";
}
bool DataVariantFormUrlencoded::parse
(
const Socket &sock,
std::string &str,
const size_t leftBytes,
std::unordered_map<std::string, std::string> &contentParams,
struct request_parameters &rp
)
{
if (str.empty() )
{
return true;
}
for (size_t var_pos = 0, var_end = 0; std::string::npos != var_end; var_pos = var_end + 1)
{
// Поиск следующего параметра
var_end = str.find('&', var_pos);
// Поиск значения параметра
size_t delimiter = str.find('=', var_pos);
if (delimiter >= var_end)
{
// Получить имя параметра
std::string var_name = Utils::urlDecode(str.substr(var_pos, std::string::npos != var_end ? var_end - var_pos : std::string::npos) );
// Сохранить параметр с пустым значением
rp.incoming_data.emplace(std::move(var_name), "");
}
else
{
// Получить имя параметра
std::string var_name = Utils::urlDecode(str.substr(var_pos, delimiter - var_pos) );
++delimiter;
// Получить значение параметра
std::string var_value = Utils::urlDecode(str.substr(delimiter, std::string::npos != var_end ? var_end - delimiter : std::string::npos) );
// Сохранить параметр и значение
rp.incoming_data.emplace(std::move(var_name), std::move(var_value) );
}
}
str.clear();
return true;
}
};