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


C++ Request::uri方法代码示例

本文整理汇总了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);
}
开发者ID:lionelc,项目名称:rstudio,代码行数:49,代码来源:SessionFiles.cpp

示例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);
   }
}
开发者ID:howarthjw,项目名称:rstudio,代码行数:31,代码来源:SessionFiles.cpp

示例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);
}
开发者ID:Wisling,项目名称:rstudio,代码行数:14,代码来源:SessionWorkbench.cpp

示例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);
}
开发者ID:kiwiroy,项目名称:rstudio,代码行数:47,代码来源:SessionContentUrls.cpp

示例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);
}
开发者ID:aszczepanski,项目名称:http-server,代码行数:21,代码来源:request_handler_get.cpp


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