当前位置: 首页>>代码示例>>C++>>正文


C++ request::header方法代码示例

本文整理汇总了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;
		}
	}
开发者ID:mnpk,项目名称:waspp,代码行数:24,代码来源:request_parser.cpp

示例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)
//.........这里部分代码省略.........
开发者ID:mnpk,项目名称:waspp,代码行数:101,代码来源:request_parser.cpp


注:本文中的request::header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。