Added query string parsing and member to request
This commit is contained in:
parent
de560e8b48
commit
a4dd2e6444
1 changed files with 19 additions and 0 deletions
|
|
@ -107,6 +107,7 @@ namespace SimpleWeb {
|
|||
Content content;
|
||||
|
||||
std::unordered_multimap<std::string, std::string, case_insensitive_hash, case_insensitive_equals> header;
|
||||
std::unordered_multimap<std::string, std::string, case_insensitive_hash, case_insensitive_equals> query_string;
|
||||
|
||||
REGEX_NS::smatch path_match;
|
||||
|
||||
|
|
@ -320,6 +321,24 @@ namespace SimpleWeb {
|
|||
request->method=line.substr(0, method_end);
|
||||
request->path=line.substr(method_end+1, path_end-method_end-1);
|
||||
|
||||
//search and populte query_string
|
||||
size_t qs_start;
|
||||
if ((qs_start = request->path.find('?')) != std::string::npos)
|
||||
{
|
||||
string qs = request->path.substr(qs_start, request->path.size() - qs_start - 1);
|
||||
REGEX_NS::regex pattern("([\\w+%]+)=?([^&]*)");
|
||||
int submatches[] = { 1, 2 };
|
||||
auto qs_begin = REGEX_NS::sregex_token_iterator(qs.begin(), qs.end(), pattern, submatches);
|
||||
auto qs_end = REGEX_NS::sregex_token_iterator();
|
||||
|
||||
for (auto i = qs_begin; i != qs_end; i++)
|
||||
{
|
||||
string key = i->str();
|
||||
string value = (++i)->str();
|
||||
request->query_string.emplace(std::make_pair(key, value));
|
||||
}
|
||||
}
|
||||
|
||||
size_t protocol_end;
|
||||
if((protocol_end=line.find('/', path_end+1))!=std::string::npos) {
|
||||
if(line.compare(path_end+1, protocol_end-path_end-1, "HTTP")!=0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue