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


C++ CDateTime::GetAsRFC1123DateTime方法代码示例

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


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

示例1: CheckRangesTestFileResponse

  void CheckRangesTestFileResponse(const CCurlFile& curl, int httpStatus = MHD_HTTP_OK, bool empty = false)
  {
    // get the HTTP header details
    const CHttpHeader& httpHeader = curl.GetHttpHeader();

    // check the protocol line for the expected HTTP status
    std::string httpStatusString = StringUtils::Format(" %d ", httpStatus);
    std::string protocolLine = httpHeader.GetProtoLine();
    ASSERT_TRUE(protocolLine.find(httpStatusString) != std::string::npos);

    // Content-Type must be "text/html"
    EXPECT_STREQ("text/plain", httpHeader.GetMimeType().c_str());
    // check Content-Length
    if (empty)
      EXPECT_STREQ("0", httpHeader.GetValue(MHD_HTTP_HEADER_CONTENT_LENGTH).c_str());
    else
      EXPECT_STREQ("20", httpHeader.GetValue(MHD_HTTP_HEADER_CONTENT_LENGTH).c_str());
    // Accept-Ranges must be "bytes"
    EXPECT_STREQ("bytes", httpHeader.GetValue(MHD_HTTP_HEADER_ACCEPT_RANGES).c_str());

    // check Last-Modified
    CDateTime lastModified;
    ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified));
    ASSERT_STREQ(lastModified.GetAsRFC1123DateTime().c_str(), httpHeader.GetValue(MHD_HTTP_HEADER_LAST_MODIFIED).c_str());

    // Cache-Control must contain "mag-age=0" and "no-cache"
    std::string cacheControl = httpHeader.GetValue(MHD_HTTP_HEADER_CACHE_CONTROL);
    EXPECT_TRUE(cacheControl.find("max-age=31536000") != std::string::npos);
    EXPECT_TRUE(cacheControl.find("public") != std::string::npos);
  }
开发者ID:bfg1981,项目名称:xbmc,代码行数:30,代码来源:TestWebServer.cpp

示例2: CDateTimeSpan

TEST_F(TestWebServer, CanGetCachedFileWithOlderIfUnmodifiedSince)
{
  // get the last modified date of the file
  CDateTime lastModified;
  ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_RANGES, lastModified));
  CDateTime lastModifiedOlder = lastModified - CDateTimeSpan(1, 0, 0, 0);

  // get the file with an older If-Unmodified-Since value
  std::string result;
  CCurlFile curl;
  curl.SetRequestHeader(MHD_HTTP_HEADER_RANGE, "");
  curl.SetRequestHeader(MHD_HTTP_HEADER_IF_UNMODIFIED_SINCE, lastModifiedOlder.GetAsRFC1123DateTime());
  ASSERT_FALSE(curl.Get(GetUrlOfTestFile(TEST_FILES_RANGES), result));
}
开发者ID:bfg1981,项目名称:xbmc,代码行数:14,代码来源:TestWebServer.cpp

示例3: CheckHtmlTestFileResponse

  void CheckHtmlTestFileResponse(const CCurlFile& curl)
  {
    // get the HTTP header details
    const CHttpHeader& httpHeader = curl.GetHttpHeader();

    // Content-Type must be "text/html"
    EXPECT_STREQ("text/html", httpHeader.GetMimeType().c_str());
    // Content-Length must be "4"
    EXPECT_STREQ("4", httpHeader.GetValue(MHD_HTTP_HEADER_CONTENT_LENGTH).c_str());
    // Accept-Ranges must be "bytes"
    EXPECT_STREQ("bytes", httpHeader.GetValue(MHD_HTTP_HEADER_ACCEPT_RANGES).c_str());

    // check Last-Modified
    CDateTime lastModified;
    ASSERT_TRUE(GetLastModifiedOfTestFile(TEST_FILES_HTML, lastModified));
    ASSERT_STREQ(lastModified.GetAsRFC1123DateTime().c_str(), httpHeader.GetValue(MHD_HTTP_HEADER_LAST_MODIFIED).c_str());

    // Cache-Control must contain "mag-age=0" and "no-cache"
    std::string cacheControl = httpHeader.GetValue(MHD_HTTP_HEADER_CACHE_CONTROL);
    EXPECT_TRUE(cacheControl.find("max-age=0") != std::string::npos);
    EXPECT_TRUE(cacheControl.find("no-cache") != std::string::npos);
  }
开发者ID:bfg1981,项目名称:xbmc,代码行数:22,代码来源:TestWebServer.cpp

示例4: FinalizeRequest

int CWebServer::FinalizeRequest(IHTTPRequestHandler *handler, int responseStatus, struct MHD_Response *response)
{
  if (handler == NULL || response == NULL)
    return MHD_NO;

  const HTTPRequest &request = handler->GetRequest();
  const HTTPResponseDetails &responseDetails = handler->GetResponseDetails();

  // if the request handler has set a content type and it hasn't been set as a header, add it 
  if (!responseDetails.contentType.empty())
    handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_TYPE, responseDetails.contentType);

  // if the request handler has set a last modified date and it hasn't been set as a header, add it
  CDateTime lastModified;
  if (handler->GetLastModifiedDate(lastModified) && lastModified.IsValid())
    handler->AddResponseHeader(MHD_HTTP_HEADER_LAST_MODIFIED, lastModified.GetAsRFC1123DateTime());

  // check if the request handler has set Cache-Control and add it if not
  if (!handler->HasResponseHeader(MHD_HTTP_HEADER_CACHE_CONTROL))
  {
    int maxAge = handler->GetMaximumAgeForCaching();
    if (handler->CanBeCached() && maxAge == 0 && !responseDetails.contentType.empty())
    {
      // don't cache HTML, CSS and JavaScript files
      if (!StringUtils::EqualsNoCase(responseDetails.contentType, "text/html") &&
          !StringUtils::EqualsNoCase(responseDetails.contentType, "text/css") &&
          !StringUtils::EqualsNoCase(responseDetails.contentType, "application/javascript"))
        maxAge = CDateTimeSpan(365, 0, 0, 0).GetSecondsTotal();
    }

    // if the response can't be cached or the maximum age is 0 force the client not to cache
    if (!handler->CanBeCached() || maxAge == 0)
      handler->AddResponseHeader(MHD_HTTP_HEADER_CACHE_CONTROL, "private, max-age=0, " HEADER_VALUE_NO_CACHE);
    else
    {
      // create the value of the Cache-Control header
      std::string cacheControl = StringUtils::Format("public, max-age=%d", maxAge);

      // check if the response contains a Set-Cookie header because they must not be cached
      if (handler->HasResponseHeader(MHD_HTTP_HEADER_SET_COOKIE))
        cacheControl += ", no-cache=\"set-cookie\"";

      // set the Cache-Control header
      handler->AddResponseHeader(MHD_HTTP_HEADER_CACHE_CONTROL, cacheControl);

      // set the Expires header
      CDateTime expiryTime = CDateTime::GetCurrentDateTime() + CDateTimeSpan(0, 0, 0, maxAge);
      handler->AddResponseHeader(MHD_HTTP_HEADER_EXPIRES, expiryTime.GetAsRFC1123DateTime());
    }
  }

  // if the request handler can handle ranges and it hasn't been set as a header, add it
  if (handler->CanHandleRanges())
    handler->AddResponseHeader(MHD_HTTP_HEADER_ACCEPT_RANGES, "bytes");
  else
    handler->AddResponseHeader(MHD_HTTP_HEADER_ACCEPT_RANGES, "none");

  // add MHD_HTTP_HEADER_CONTENT_LENGTH
  if (responseDetails.totalLength > 0)
    handler->AddResponseHeader(MHD_HTTP_HEADER_CONTENT_LENGTH, StringUtils::Format("%" PRIu64, responseDetails.totalLength));

  // add all headers set by the request handler
  for (std::multimap<std::string, std::string>::const_iterator it = responseDetails.headers.begin(); it != responseDetails.headers.end(); ++it)
    AddHeader(response, it->first, it->second);

#ifdef WEBSERVER_DEBUG
  std::multimap<std::string, std::string> headerValues;
  GetRequestHeaderValues(request.connection, MHD_RESPONSE_HEADER_KIND, headerValues);

  CLog::Log(LOGDEBUG, "webserver [OUT] %s %d %s", request.version.c_str(), responseStatus, request.pathUrlFull.c_str());

  for (std::multimap<std::string, std::string>::const_iterator header = headerValues.begin(); header != headerValues.end(); ++header)
    CLog::Log(LOGDEBUG, "webserver [OUT] %s: %s", header->first.c_str(), header->second.c_str());
#endif

  int ret = MHD_queue_response(request.connection, responseStatus, response);
  MHD_destroy_response(response);
  delete handler;

  return ret;
}
开发者ID:Karlson2k,项目名称:xbmc,代码行数:81,代码来源:WebServer.cpp

示例5: CreateFileDownloadResponse


//.........这里部分代码省略.........
          mimeType = "multipart/byteranges; boundary=" + context->boundary;

          // build part of the boundary with the optional Content-Type header
          // "--<boundary>\r\nContent-Type: <content-type>\r\n
          context->boundaryWithHeader = "\r\n--" + context->boundary + "\r\n";
          if (!context->contentType.empty())
            context->boundaryWithHeader += "Content-Type: " + context->contentType + "\r\n";

          // for every range, we need to add a boundary with header
          for (HttpRanges::const_iterator range = context->ranges.begin(); range != context->ranges.end(); range++)
          {
            // we need to temporarily add the Content-Range header to the
            // boundary to be able to determine the length
            string completeBoundaryWithHeader = context->boundaryWithHeader;
            completeBoundaryWithHeader += StringUtils::Format("Content-Range: " CONTENT_RANGE_FORMAT,
                                                              range->first, range->second, range->second - range->first + 1);
            completeBoundaryWithHeader += "\r\n\r\n";

            totalLength += completeBoundaryWithHeader.size();
          }
          // and at the very end a special end-boundary "\r\n--<boundary>--"
          totalLength += 4 + context->boundary.size() + 2;
        }

        // set the initial write position
        context->writePosition = context->ranges.begin()->first;

        // create the response object
        response = MHD_create_response_from_callback(totalLength,
                                                     2048,
                                                     &CWebServer::ContentReaderCallback, context,
                                                     &CWebServer::ContentReaderFreeCallback);
      }

      if (response == NULL)
      {
        file->Close();
        delete file;
        delete context;
        return MHD_NO;
      }

      // add Content-Range header
      if (ranged)
        AddHeader(response, "Content-Range", StringUtils::Format(CONTENT_RANGE_FORMAT, firstPosition, lastPosition, fileLength).c_str());
    }
    else
    {
      getData = false;

      CStdString contentLength;
      contentLength.Format("%" PRId64, fileLength);

      response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
      if (response == NULL)
      {
        file->Close();
        delete file;
        return MHD_NO;
      }
      AddHeader(response, "Content-Length", contentLength);
    }

    // add "Accept-Ranges: bytes" header
    AddHeader(response, "Accept-Ranges", "bytes");

    // set the Content-Type header
    if (!mimeType.empty())
      AddHeader(response, "Content-Type", mimeType.c_str());

    // set the Last-Modified header
    if (lastModified.IsValid())
      AddHeader(response, "Last-Modified", lastModified.GetAsRFC1123DateTime());

    // set the Expires header
    CDateTime expiryTime = CDateTime::GetCurrentDateTime();
    if (StringUtils::EqualsNoCase(mimeType, "text/html") ||
        StringUtils::EqualsNoCase(mimeType, "text/css") ||
        StringUtils::EqualsNoCase(mimeType, "application/javascript"))
      expiryTime += CDateTimeSpan(1, 0, 0, 0);
    else
      expiryTime += CDateTimeSpan(365, 0, 0, 0);
    AddHeader(response, "Expires", expiryTime.GetAsRFC1123DateTime());

    // only close the CFile instance if libmicrohttpd doesn't have to grab the data of the file
    if (!getData)
    {
      file->Close();
      delete file;
    }
  }
  else
  {
    delete file;
    CLog::Log(LOGERROR, "WebServer: Failed to open %s", strURL.c_str());
    return SendErrorResponse(connection, MHD_HTTP_NOT_FOUND, methodType);
  }

  return MHD_YES;
}
开发者ID:Micromax-56,项目名称:xbmc,代码行数:101,代码来源:WebServer.cpp

示例6: CreateFileDownloadResponse

int CWebServer::CreateFileDownloadResponse(struct MHD_Connection *connection, const string &strURL, HTTPMethod methodType, struct MHD_Response *&response, int &responseCode)
{
  CFile *file = new CFile();

  if (file->Open(strURL, READ_NO_CACHE))
  {
    bool getData = true;
    if (methodType != HEAD)
    {
      if (methodType == GET)
      {
        string ifModifiedSince = GetRequestHeaderValue(connection, MHD_HEADER_KIND, "If-Modified-Since");
        if (!ifModifiedSince.empty())
        {
          CDateTime ifModifiedSinceDate;
          ifModifiedSinceDate.SetFromRFC1123DateTime(ifModifiedSince);

          struct __stat64 statBuffer;
          if (file->Stat(&statBuffer) == 0)
          {
            struct tm *time = localtime((time_t *)&statBuffer.st_mtime);
            if (time != NULL)
            {
              CDateTime lastModified = *time;
              if (lastModified.GetAsUTCDateTime() <= ifModifiedSinceDate)
              {
                getData = false;
                response = MHD_create_response_from_data (0, NULL, MHD_NO, MHD_NO);
                responseCode = MHD_HTTP_NOT_MODIFIED;
              }
            }
          }
        }
      }

      if (getData)
        response = MHD_create_response_from_callback(file->GetLength(),
                                                     2048,
                                                     &CWebServer::ContentReaderCallback, file,
                                                     &CWebServer::ContentReaderFreeCallback);
      if (response == NULL)
      {
        file->Close();
        delete file;
        return MHD_NO;
      }
    }
    else
    {
      getData = false;

      CStdString contentLength;
      contentLength.Format("%I64d", file->GetLength());

      response = MHD_create_response_from_data (0, NULL, MHD_NO, MHD_NO);
      if (response == NULL)
      {
        file->Close();
        delete file;
        return MHD_NO;
      }
      MHD_add_response_header(response, "Content-Length", contentLength);
    }

    // set the Content-Type header
    CStdString ext = URIUtils::GetExtension(strURL);
    ext = ext.ToLower();
    const char *mime = CreateMimeTypeFromExtension(ext.c_str());
    if (mime)
      MHD_add_response_header(response, "Content-Type", mime);

    // set the Last-Modified header
    struct __stat64 statBuffer;
    if (file->Stat(&statBuffer) == 0)
    {
      struct tm *time = localtime((time_t *)&statBuffer.st_mtime);
      if (time != NULL)
      {
        CDateTime lastModified = *time;
        MHD_add_response_header(response, "Last-Modified", lastModified.GetAsRFC1123DateTime());
      }
    }

    // set the Expires header
    CDateTime expiryTime = CDateTime::GetCurrentDateTime();
    if (mime && strncmp(mime, "text/html", 9) == 0)
      expiryTime += CDateTimeSpan(1, 0, 0, 0);
    else
      expiryTime += CDateTimeSpan(365, 0, 0, 0);
    MHD_add_response_header(response, "Expires", expiryTime.GetAsRFC1123DateTime());

    // only close the CFile instance if libmicrohttpd doesn't have to grab the data of the file
    if (!getData)
    {
      file->Close();
      delete file;
    }
  }
  else
  {
//.........这里部分代码省略.........
开发者ID:2BReality,项目名称:xbmc,代码行数:101,代码来源:WebServer.cpp

示例7: CreateFileDownloadResponse


//.........这里部分代码省略.........
      else
        responseCode = MHD_HTTP_PARTIAL_CONTENT;

      // remember the total number of ranges
      context->rangeCount = context->ranges.size();
      // remember the total length
      totalLength = context->rangesLength;

      // we need to remember whether we are ranged because the range length
      // might change and won't be reliable anymore for length comparisons
      ranged = context->rangeCount > 1 || context->rangesLength < fileLength;

      // adjust the MIME type and range length in case of multiple ranges
      // which requires multipart boundaries
      if (context->rangeCount > 1)
      {
        context->boundary = GenerateMultipartBoundary();
        mimeType = "multipart/byteranges; boundary=" + context->boundary;

        // build part of the boundary with the optional Content-Type header
        // "--<boundary>\r\nContent-Type: <content-type>\r\n
        context->boundaryWithHeader = HEADER_NEWLINE HEADER_BOUNDARY + context->boundary + HEADER_NEWLINE;
        if (!context->contentType.empty())
          context->boundaryWithHeader += MHD_HTTP_HEADER_CONTENT_TYPE ": " + context->contentType + HEADER_NEWLINE;

        // for every range, we need to add a boundary with header
        for (HttpRanges::const_iterator range = context->ranges.begin(); range != context->ranges.end(); range++)
        {
          // we need to temporarily add the Content-Range header to the
          // boundary to be able to determine the length
          string completeBoundaryWithHeader = context->boundaryWithHeader;
          completeBoundaryWithHeader += StringUtils::Format(MHD_HTTP_HEADER_CONTENT_RANGE ": " CONTENT_RANGE_FORMAT,
                                                            range->first, range->second, range->second - range->first + 1);
          completeBoundaryWithHeader += HEADER_SEPARATOR;

          totalLength += completeBoundaryWithHeader.size();
        }
        // and at the very end a special end-boundary "\r\n--<boundary>--"
        totalLength += strlen(HEADER_SEPARATOR) + strlen(HEADER_BOUNDARY) + context->boundary.size() + strlen(HEADER_BOUNDARY);
      }

      // set the initial write position
      context->writePosition = context->ranges.begin()->first;

      // create the response object
      response = MHD_create_response_from_callback(totalLength, 2048,
                                                   &CWebServer::ContentReaderCallback,
                                                   context.get(),
                                                   &CWebServer::ContentReaderFreeCallback);
      if (response == NULL)
        return MHD_NO;
        
      context.release(); // ownership was passed to mhd
    }

    // add Content-Range header
    if (ranged)
      AddHeader(response, MHD_HTTP_HEADER_CONTENT_RANGE, StringUtils::Format(CONTENT_RANGE_FORMAT, firstPosition, lastPosition, fileLength));
  }
  else
  {
    getData = false;

    std::string contentLength = StringUtils::Format("%" PRId64, fileLength);

    response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
    if (response == NULL)
      return MHD_NO;

    AddHeader(response, MHD_HTTP_HEADER_CONTENT_LENGTH, contentLength);
  }

  // add "Accept-Ranges: bytes" header
  AddHeader(response, MHD_HTTP_HEADER_ACCEPT_RANGES, "bytes");

  // set the Content-Type header
  if (!mimeType.empty())
    AddHeader(response, MHD_HTTP_HEADER_CONTENT_TYPE, mimeType);

  // set the Last-Modified header
  if (lastModified.IsValid())
    AddHeader(response, MHD_HTTP_HEADER_LAST_MODIFIED, lastModified.GetAsRFC1123DateTime());

  // set the Expires header
  CDateTime now = CDateTime::GetCurrentDateTime();
  CDateTime expiryTime = now;
  if (StringUtils::EqualsNoCase(mimeType, "text/html") ||
      StringUtils::EqualsNoCase(mimeType, "text/css") ||
      StringUtils::EqualsNoCase(mimeType, "application/javascript"))
    expiryTime += CDateTimeSpan(1, 0, 0, 0);
  else
    expiryTime += CDateTimeSpan(365, 0, 0, 0);
  AddHeader(response, MHD_HTTP_HEADER_EXPIRES, expiryTime.GetAsRFC1123DateTime());

  // set the Cache-Control header
  int maxAge = (expiryTime - now).GetSecondsTotal();
  AddHeader(response, MHD_HTTP_HEADER_CACHE_CONTROL, StringUtils::Format("max-age=%d, public", maxAge));

  return MHD_YES;
}
开发者ID:Avbrella,项目名称:xbmc,代码行数:101,代码来源:WebServer.cpp


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