本文整理汇总了C++中Response::addHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ Response::addHeader方法的具体用法?C++ Response::addHeader怎么用?C++ Response::addHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::addHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setShouldConnectionBeClosed
void setShouldConnectionBeClosed(const Request& request, Response& response)
{
auto headers = request.getSortedHeaders();
auto const& connection = headers["Connection"];
if (boost::iequals(connection, CLOSE))
{
response.connectionShouldBeClosed(true);
return;
}
if (boost::iequals(connection, KEEPALIVE))
{
response.connectionShouldBeClosed(false);
response.addHeader("Connection", KEEPALIVE);
return;
}
if (request.major == 1 && request.minor == 1)
{
response.connectionShouldBeClosed(false);
return;
}
response.connectionShouldBeClosed(true);
return;
}
示例2: handleRequest
static void handleRequest(Response& response) {
response.addHeader("Content-Type", "text/html");
response <<
"<html><body>POST example."
"<form method=\"POST\" action=\"" << wf::router().uri("post") << "\">"
"Input 1: <input type=\"text\" name=\"input_1\" /> <br/>"
"Input 2: <input type=\"text\" name=\"input_2\" /> <br/>"
"<input type=\"submit\" />"
"</form></body></html>";
}
示例3: handleConnections
void HTTPServer::handleConnections (HTTPServer *server)
{
int r;
#ifdef WIN32
int addrSz;
#else
socklen_t addrSz;
#endif
SOCKADDR_IN addr;
SOCKET cli;
while (server->isRunning)
{
r = listen (server->srv, 50);
if (r == SOCKET_ERROR)
{
#ifdef WIN32
Sleep (500);
#else
sleep (1);
#endif
continue;
}
addrSz = sizeof addr;
cli = accept (server->srv, (SOCKADDR*)&addr, &addrSz);
if (cli == INVALID_SOCKET)
continue;
Response resp (cli); // doesn't throw exceptions.
try {
Request req (cli, &addr); // may throw exceptions.
reqCallback *cb = getRequestHandler (&server->rootNode, req.getPath());
if (cb == NULL)
{
// error 404
resp.setStatus (404, "Not Found");
resp.addHeader ("Content-Type", "text/html; charset=US-ASCII");
stringstream stream;
stream << "<html>";
stream << "<head><title>Not Found</title></head>";
stream << "<body><h1>Not Found</h1><div>The server couldn't find the request resource.</div><br /><hr /><div style=\"font-size:small;text-align:center;\">© 2013 Naim A. | <a href=\"http://udpt.googlecode.com/\">The UDPT Project</a></div></body>";
stream << "</html>";
string str = stream.str();
resp.write (str.c_str(), str.length());
}
else
{
try {
cb (server, &req, &resp);
} catch (...)
{
resp.setStatus(500, "Internal Server Error");
resp.addHeader ("Content-Type", "text/html; charset=US-ASCII");
stringstream stream;
stream << "<html>";
stream << "<head><title>Internal Server Error</title></head>";
stream << "<body><h1>Internal Server Error</h1><div>An Error Occurred while trying to process your request.</div><br /><hr /><div style=\"font-size:small;text-align:center;\">© 2013 Naim A. | <a href=\"http://udpt.googlecode.com/\">The UDPT Project</a></div></body>";
stream << "</html>";
string str = stream.str();
resp.write (str.c_str(), str.length());
}
}
resp.finalize();
} catch (ServerException &e)
{
// Error 400 Bad Request!
}
closesocket (cli);
}
}