本文整理汇总了C++中http::Request::uri方法的典型用法代码示例。如果您正苦于以下问题:C++ Request::uri方法的具体用法?C++ Request::uri怎么用?C++ Request::uri使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http::Request
的用法示例。
在下文中一共展示了Request::uri方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handleFilesRequest
void handleFilesRequest(const http::Request& request,
http::Response* pResponse)
{
Options& options = session::options();
if (options.programMode() != kSessionProgramModeServer)
{
pResponse->setError(http::status::NotFound,
request.uri() + " not found");
return;
}
// get prefix and uri
std::string prefix = "/files/";
std::string uri = request.uri();
// validate the uri
if (prefix.length() >= uri.length() || // prefix longer than uri
uri.find(prefix) != 0 || // uri doesn't start with prefix
uri.find("..") != std::string::npos) // uri has inavlid char sequence
{
pResponse->setError(http::status::NotFound,
request.uri() + " not found");
return;
}
// compute path to file
int prefixLen = prefix.length();
std::string relativePath = http::util::urlDecode(uri.substr(prefixLen));
if (relativePath.empty())
{
pResponse->setError(http::status::NotFound, request.uri() + " not found");
return;
}
// complete path to file
FilePath filePath = module_context::userHomePath().complete(relativePath);
// no directory listing available
if (filePath.isDirectory())
{
pResponse->setError(http::status::NotFound,
"No listing available for " + request.uri());
return;
}
pResponse->setNoCacheHeaders();
pResponse->setFile(filePath, request);
}
示例2: handleFileExportRequest
void handleFileExportRequest(const http::Request& request,
http::Response* pResponse)
{
// see if this is a single or multiple file request
std::string file = request.queryParamValue("file");
if (!file.empty())
{
// resolve alias and ensure that it exists
FilePath filePath = module_context::resolveAliasedPath(file);
if (!filePath.exists())
{
pResponse->setNotFoundError(request.uri());
return;
}
// get the name
std::string name = request.queryParamValue("name");
if (name.empty())
{
pResponse->setError(http::status::BadRequest, "name not specified");
return;
}
// download as attachment
setAttachmentResponse(request, name, filePath, pResponse);
}
else
{
handleMultipleFileExportRequest(request, pResponse);
}
}
示例3: handleFileShow
void handleFileShow(const http::Request& request, http::Response* pResponse)
{
// get the file path
FilePath filePath(request.queryParamValue("path"));
if (!filePath.exists())
{
pResponse->setNotFoundError(request.uri());
return;
}
// send it back
pResponse->setCacheWithRevalidationHeaders();
pResponse->setCacheableFile(filePath, request);
}
示例4: handleContentRequest
void handleContentRequest(const http::Request& request, http::Response* pResponse)
{
// get content file info
std::string title;
FilePath contentFilePath;
Error error = contentFileInfo(request.uri(), &title, &contentFilePath);
if (error)
{
pResponse->setError(error);
return;
}
// set private cache forever headers
pResponse->setPrivateCacheForeverHeaders();
// set file
pResponse->setFile(contentFilePath, request);
bool isUtf8 = true;
if (boost::algorithm::starts_with(contentFilePath.mimeContentType(), "text/"))
{
// If the content looks like valid UTF-8, assume it is. Otherwise, assume
// it's the system encoding.
std::string contents;
error = core::readStringFromFile(contentFilePath, &contents);
if (!error)
{
for (std::string::iterator pos = contents.begin(); pos != contents.end(); )
{
error = string_utils::utf8Advance(pos, 1, contents.end(), &pos);
if (error)
{
isUtf8 = false;
break;
}
}
}
}
// reset content-type with charset
pResponse->setContentType(contentFilePath.mimeContentType() +
std::string("; charset=") +
(isUtf8 ? "UTF-8" : ::locale2charset(NULL)));
// set title header
pResponse->setHeader("Title", title);
}
示例5: HandleRequest
void RequestHandlerGET::HandleRequest(
const http::Request& request, http::Response* response) const {
string path;
string rest;
string fragment;
if (!DecodeURL(request.uri(), &path, &rest, &fragment)) {
*response = Response::StockResponse(Response::BAD_REQUEST);
return;
}
LOG_DEBUG(logger_, "path: " << path)
LOG_DEBUG(logger_, "rest: " << rest)
LOG_DEBUG(logger_, "fragment: " << fragment)
string full_path = root_directory_ + path;
LOG_DEBUG(logger_, full_path)
CreateResponse(full_path, response);
}