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


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

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

示例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>";
 }
开发者ID:tbknl,项目名称:wf,代码行数:10,代码来源:post.cpp

示例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;\">&copy; 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;\">&copy; 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);
			}
		}
开发者ID:augustt198,项目名称:udpt,代码行数:72,代码来源:httpserver.cpp


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