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


C++ Content::execute方法代码示例

本文整理汇总了C++中Content::execute方法的典型用法代码示例。如果您正苦于以下问题:C++ Content::execute方法的具体用法?C++ Content::execute怎么用?C++ Content::execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Content的用法示例。


在下文中一共展示了Content::execute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: result

int Jupiter::HTTP::Server::Data::process_request(HTTPSession &session)
{
	Jupiter::ReadableString::TokenizeResult<Jupiter::Reference_String> lines = Jupiter::ReferenceString::tokenize(session.request, STRING_LITERAL_AS_REFERENCE(ENDL));
	HTTPCommand command = HTTPCommand::NONE_SPECIFIED;
	Content *content = nullptr;
	Jupiter::ReferenceString query_string;
	Jupiter::ReferenceString first_token;
	size_t index = 0;
	size_t span;

	auto get_line_offset = [&session, &lines](size_t index)
	{
		size_t offset = 0;
		while (index != 0)
			offset += lines.tokens[--index].size() + 2;
		return offset;
	};

	while (index != lines.token_count)
	{
		Jupiter::ReferenceString &line = lines.tokens[index++];

		// trim front-end spaces.
		span = line.span(" "_jrs);
		if (span != 0)
			line.shiftRight(span);

		if (line.isEmpty()) // end of http request
		{
			Jupiter::String result(256);
			switch (command)
			{
			case HTTPCommand::GET:
			case HTTPCommand::HEAD:
				if (content != nullptr)
				{
					// 200 (success)
					Jupiter::ReadableString *content_result = content->execute(query_string);

					switch (session.version)
					{
					default:
					case HTTPVersion::HTTP_1_0:
						result = "HTTP/1.0 200 OK"_jrs ENDL;
						break;
					case HTTPVersion::HTTP_1_1:
						result = "HTTP/1.1 200 OK"_jrs ENDL;
						break;
					}

					result += "Date: "_jrs;
					char *time_header = html_time();
					result += time_header;
					delete[] time_header;
					result += ENDL;

					result += "Server: "_jrs JUPITER_VERSION ENDL;

					result += Jupiter::StringS::Format("Content-Length: %u" ENDL, content_result->size());

					if (session.keep_alive)
						result += "Connection: keep-alive"_jrs ENDL;
					else
						result += "Connection: close"_jrs ENDL;

					result += "Content-Type: "_jrs;
					if (content->type == nullptr)
						result += Jupiter::HTTP::Content::Type::Text::PLAIN;
					else
						result += *content->type;
					if (content->charset != nullptr)
					{
						result += "; charset="_jrs;
						result += *content->charset;
					}
					result += ENDL;

					if (content->language != nullptr)
					{
						result += "Content-Language: "_jrs;
						result += *content->language;
						result += ENDL;
					}

					result += ENDL;
					if (command == HTTPCommand::GET)
						result += *content_result;

					if (content->free_result)
						delete content_result;

					session.sock.send(result);
				}
				else
				{
					// 404 (not found)

					switch (session.version)
					{
					default:
//.........这里部分代码省略.........
开发者ID:JAJames,项目名称:Jupiter,代码行数:101,代码来源:HTTP_Server.cpp


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