本文整理汇总了C++中HTTPServerRequest::getPath方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPServerRequest::getPath方法的具体用法?C++ HTTPServerRequest::getPath怎么用?C++ HTTPServerRequest::getPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPServerRequest
的用法示例。
在下文中一共展示了HTTPServerRequest::getPath方法的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();
}
}
}
}