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


C++ Response::finalize方法代码示例

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


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

示例1: received

/** Called whenever new data arrives in the input buffer. Called on the Connection's
 * thread, which makes it unnecessary to have a lock for the input buffer. */
void Connection::received()
{
	//Try to parse the HTTP request that was received.
	unsigned int consumed = 0;
	HTTP::Request *request = HTTP::Request::fromString(inputBuffer, &consumed);
	if (consumed > 0) {
		inputBuffer.assign(inputBuffer, consumed, inputBuffer.length() - consumed);
	}
	if (!request) return;
	clog << "processing request" << endl;

	clog << request->path << endl;



	if(request->path.at(0) != '/')
	{
		clog << "invalid request" << endl;
		HTTP::Response r;
		r.statusCode = 404;
		r.statusText = string("Requested object ") + request->path + " not found.";
		r.finalize();
		write(r);
		close();
		return;
	}
	int i,j;
	for(i = 1; i < request->path.length() &&
		request->path.at(i) != '/'; i++)
	{}
	if (i == request->path.length())
	{
		clog << "invalid request" << endl;
		HTTP::Response r;
		r.statusCode = 400;
		r.statusText = string("Requested object ") + request->path + " not found.";
		r.finalize();
		write(r);
		close();
		return;		
	}
	std::string command = request->path.substr(0,i);
	clog << command << endl;
	if (command == "/play")
	{
		for(j = i+1; j < request->path.length() &&
			request->path.at(j) != '/'; j++)
		{}
		clog << "j= " << j << endl << "length= " <<
			request->path.length() << endl;
		if (j == request->path.length())
		{
			clog << "invalid request" << endl;
			HTTP::Response r;
			r.statusCode = 400;
			r.statusText = string("Requested object ") + request->path + " not found.";
			r.finalize();
			write(r);
			close();
			return;		
		}
		std::string host = request->path.substr(i+1,j-(i+1));
		std::string uuid = request->path.substr(j+1);

		clog << "Creating new session.\n";

		//create a new session
		Session * session = player->makeSession();
		clog << "Created new session.\n";
		session->play(host, uuid);
	}
	else if (command == "/stop")
	{

	}
	else {
		clog << "unable to serve requested object " << request->path << endl;
		HTTP::Response r;
		r.statusCode = 404;
		r.statusText = string("Requested object ") + request->path + " not found.";
		r.finalize();
		write(r);
		close();
	}
}
开发者ID:fabianschuiki,项目名称:Auris,代码行数:87,代码来源:Connection.cpp


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