本文整理汇总了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();
}
}