本文整理汇总了C++中http_request::set_method方法的典型用法代码示例。如果您正苦于以下问题:C++ http_request::set_method方法的具体用法?C++ http_request::set_method怎么用?C++ http_request::set_method使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_request
的用法示例。
在下文中一共展示了http_request::set_method方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_line
boost::tribool request_parser::parse_line(http_request &request, const std::string &line)
{
if (line.empty() || line[line.size() - 1] != '\r')
return false;
const bool is_empty_line = line.compare(0, line.size(), "\r", 1) == 0;
switch (m_state_new) {
case request_line: {
if (is_empty_line) {
// Ignore CRLF characters between requests in Keep-Alive connection
return boost::indeterminate;
}
const auto first_space = line.find(' ');
if (first_space == std::string::npos)
return false;
request.set_method(line.substr(0, first_space));
const auto second_space = line.find(' ', first_space + 1);
if (second_space == std::string::npos)
return false;
request.set_url(line.substr(first_space + 1, second_space - first_space - 1));
if (line.compare(second_space + 1, 5, "HTTP/", 5) != 0)
return false;
const auto version_major_start = second_space + 1 + 5;
const auto dot = line.find('.', version_major_start);
if (dot == std::string::npos)
return false;
const auto version_minor_end = line.find('\r', dot);
if (version_minor_end == std::string::npos)
return false;
boost::tribool result = boost::indeterminate;
const auto major_version = parse_int(line.data() + version_major_start, line.data() + dot, result);
const auto minor_version = parse_int(line.data() + dot + 1, line.data() + version_minor_end, result);
request.set_http_version(major_version, minor_version);
m_state_new = header_line;
return result;
}
case header_line: {
if (!m_header.first.empty() && (line[0] == ' ' || line[0] == '\t')) {
// any number of LWS is allowed after field, rfc 2068
auto begin = line.begin() + 1;
auto end = line.end();
trim_line(begin, end);
m_header.second += ' ';
m_header.second.append(begin, end);
return boost::indeterminate;
}
if (!m_header.first.empty()) {
request.headers().add(m_header);
m_header.first.resize(0);
m_header.second.resize(0);
}
if (is_empty_line) {
return true;
}
const auto colon = line.find(':');
if (colon == std::string::npos)
return false;
auto name_begin = line.begin();
auto name_end = line.begin() + colon;
trim_line(name_begin, name_end);
m_header.first.assign(name_begin, name_end);
auto value_begin = line.begin() + colon + 1;
auto value_end = line.end();
trim_line(value_begin, value_end);
m_header.second.assign(value_begin, value_end);
return boost::indeterminate;
}
}
return false;
}