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


C++ HTTPServerRequest::getAuthUsername方法代码示例

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


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

示例1: handleRequest

void HTTPServerRequestDespatcher::handleRequest(HTTPServerRequest &request, std::string &response)
{
	if (m_authenticationType != eHTTPAuthNone)
	{
		if (!request.hasAuthenticationHeader())
		{
			HTTPServerAuthenticationResponse resp;
			response = resp.responseString();
			return;
		}
		
		// otherwise, see if the authentication is valid
		if (!request.isAcceptedAuthenticationHeader())
		{
			// TODO: do this properly
			HTTPServerAuthenticationResponse resp;
			response = resp.responseString();
			return;
		}
		
		// now check username and password
		const std::string& authUsername = request.getAuthUsername();
		const std::string& authPassword = request.getAuthPassword();
		
		if (!m_server.areAuthCredentialsValid(authUsername, authPassword))
		{
			// TODO: again, do this properly, maybe with some counter to delay responses...
			HTTPServerAuthenticationResponse resp;
			response = resp.responseString();
			return;
		}
	}
	
	std::map<std::string, MFP>::iterator itFind = m_requestMappings.find(request.getPath());

	if (itFind != m_requestMappings.end())
	{
		MFP fp = (*itFind).second;

		(this->*fp)(request, response);
	}
	else
	{
		std::string requestedPath = request.getPath();
		if (requestedPath.size() > 1 && requestedPath.substr(0, 1) == "/") // an actual relative path was specified
		{
			requestedPath = requestedPath.substr(1); // knock off the leading slash
		}
		else if (requestedPath.size() == 1 && requestedPath == "/")
		{
			// default is index.html
			requestedPath = "index.html";
		}

		if (m_webContentPath.empty())
		{
			std::string content = "<html>\n<head><title>Sitemon Web Interface</title></head>\n<body>\n";
			content += "<h3>Sitemon Web Interface</h3>\nError: Web Content Path not configured.\n</body>\n</html>\n";

			HTTPServerResponse resp(500, content);
			response = resp.responseString();
		}
		else
		{
			if (requestedPath.find("..") != -1) // try and guard against obvious exploits
			{
				HTTPServerResponse resp1(500, "<h3>Error occured.</h3>");

				response = resp1.responseString();
			}
			else
			{
				std::string filePath = m_webContentPath + requestedPath;

				HTTPServerFileResponse resp(filePath);
				response = resp.responseString();
			}
		}
	}
}
开发者ID:ppearson,项目名称:sitemon2,代码行数:80,代码来源:http_server_request_despatcher.cpp


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