Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
add cookie parse
Browse files Browse the repository at this point in the history
Signed-off-by: manageryzy <manageryzy@gmail.com>
  • Loading branch information
manageryzy committed Jun 20, 2017
1 parent 8a00046 commit 937370c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server_http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,27 @@ namespace SimpleWeb {
return result;
}

std::unordered_multimap<std::string, std::string, CaseInsensitiveHash, CaseInsensitiveEqual> parse_cookies()
{
std::unordered_multimap<std::string, std::string, CaseInsensitiveHash, CaseInsensitiveEqual> result;
auto it = this->header.find("Cookie");
if(it==this->header.end()) return result;

auto cookie = it->second;

static regex::regex pattern("([\\w+%]+)=?([^;]*)");
int submatches[] = { 1, 2 };
auto it_begin = regex::sregex_token_iterator(cookie.begin(), cookie.end(), pattern, submatches);
auto it_end = regex::sregex_token_iterator();
for (auto it = it_begin; it != it_end; ++it) {
auto submatch1 = it->str();
auto submatch2 = (++it)->str();
result.emplace(submatch1, submatch2);
}

return result;
}

private:
Request(const socket_type &socket): content(streambuf) {
try {
Expand Down

0 comments on commit 937370c

Please sign in to comment.