Made a function for parameter parsing
This commit is contained in:
parent
c0c31f5093
commit
b8ca3f6d13
29
src/http.cpp
29
src/http.cpp
|
@ -41,17 +41,34 @@ const Request http::parse_request(const string &request)
|
|||
if (pos_digest != std::string::npos)
|
||||
{
|
||||
digest = digest.substr(0, pos_digest);
|
||||
std::size_t pos_size = request.find("s=", pos_digest);
|
||||
if (pos_size != std::string::npos)
|
||||
|
||||
string answer;
|
||||
answer = get_parameter(request, "s");
|
||||
if (!answer.empty())
|
||||
{
|
||||
size = static_cast<uint16_t>(std::stoul(request.substr(pos_size + 2)));
|
||||
size = static_cast<uint16_t>(std::stoul(answer));
|
||||
}
|
||||
pos_size = request.find("size=", pos_digest);
|
||||
if (pos_size != std::string::npos)
|
||||
else
|
||||
{
|
||||
size = static_cast<uint16_t>(std::stoul(request.substr(pos_size + 5)));
|
||||
answer = get_parameter(request, "size");
|
||||
if (!answer.empty())
|
||||
{
|
||||
size = static_cast<uint16_t>(std::stoul(answer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { digest, size };
|
||||
}
|
||||
|
||||
const string http::get_parameter(const string &request, const string ¶meter)
|
||||
{
|
||||
std::size_t pos = request.find(parameter + "=");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
pos += parameter.length();
|
||||
return request.substr(pos, request.find('&', pos));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@ namespace http // http.cpp
|
|||
};
|
||||
|
||||
const Request parse_request(const string &request);
|
||||
const string get_parameter(const string &request, const string ¶meter);
|
||||
}
|
||||
|
||||
namespace hash // hash.cpp
|
||||
|
|
Loading…
Reference in New Issue