本文整理汇总了C++中request::header方法的典型用法代码示例。如果您正苦于以下问题:C++ request::header方法的具体用法?C++ request::header怎么用?C++ request::header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类request
的用法示例。
在下文中一共展示了request::header方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_cookies
void request_parser::parse_cookies(request& req)
{
std::string data = req.header("Cookie");
if (data.empty())
{
return;
}
std::string::size_type pos;
std::string::size_type old_pos = 0;
while (true)
{
pos = data.find(";", old_pos);
if (pos == std::string::npos)
{
parse_cookie(req, data.substr(old_pos));
return;
}
parse_cookie(req, data.substr(old_pos, pos - old_pos));
old_pos = pos + 1;
}
}
示例2: parse_content
void request_parser::parse_content(request& req)
{
if (req.content.empty())
{
return;
}
std::string standard_type = "application/x-www-form-urlencoded";
std::string multipart_type = "multipart/form-data";
std::string content_type = req.header("Content-Type");
if (content_type.empty() || strings_are_equal(content_type, standard_type, standard_type.size()))
{
std::string name, value;
std::string::size_type pos;
std::string::size_type old_pos = 0;
while (true)
{
pos = req.content.find_first_of("&=", old_pos);
if (pos == std::string::npos)
{
break;
}
if (req.content.at(pos) == '&')
{
const char* c_str_ = req.content.c_str() + old_pos;
while (*c_str_ == '&')
{
++c_str_;
++old_pos;
}
if (old_pos >= pos)
{
old_pos = ++pos;
continue;
}
name = percent_decode(req.content.substr(old_pos, pos - old_pos));
req.params.push_back(name_value(name, std::string()));
old_pos = ++pos;
continue;
}
name = percent_decode(req.content.substr(old_pos, pos - old_pos));
old_pos = ++pos;
pos = req.content.find_first_of(";&", old_pos);
value = percent_decode(req.content.substr(old_pos, pos - old_pos));
req.params.push_back(name_value(name, value));
if (pos == std::string::npos)
{
break;
}
old_pos = ++pos;
}
}
else if (strings_are_equal(multipart_type, content_type, multipart_type.size()))
{
std::string b_type = "boundary=";
std::string::size_type pos = content_type.find(b_type);
std::string sep1 = content_type.substr(pos + b_type.size());
if (sep1.find(";") != std::string::npos)
{
sep1 = sep1.substr(0, sep1.find(";"));
}
sep1.append("\r\n");
sep1.insert(0, "--");
std::string sep2 = content_type.substr(pos + b_type.size());
if (sep2.find(";") != std::string::npos)
{
sep2 = sep2.substr(0, sep2.find(";"));
}
sep2.append("--\r\n");
sep2.insert(0, "--");
std::string::size_type start = req.content.find(sep1);
std::string::size_type sep_size = sep1.size();
std::string::size_type old_pos = start + sep_size;
while (true)
{
pos = req.content.find(sep1, old_pos);
if (pos == std::string::npos)
{
break;
}
parse_multipart_content(req, req.content.substr(old_pos, pos - old_pos));
old_pos = pos + sep_size;
}
pos = req.content.find(sep2, old_pos);
if (pos != std::string::npos)
//.........这里部分代码省略.........