本文整理汇总了C++中HttpServletRequest::GetDateHeader方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpServletRequest::GetDateHeader方法的具体用法?C++ HttpServletRequest::GetDateHeader怎么用?C++ HttpServletRequest::GetDateHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest::GetDateHeader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Service
void HttpServlet::Service(HttpServletRequest& request, HttpServletResponse& response)
{
std::string method = request.GetMethod();
if (method == METHOD_GET)
{
long long lastModified = GetLastModified(request);
if (lastModified == -1)
{
// servlet doesn't support if-modified-since, no reason
// to go through further expensive logic
DoGet(request, response);
}
else
{
long long ifModifiedSince = request.GetDateHeader(HEADER_IFMODSINCE);
std::cout << "ifModifiedSince: " << ifModifiedSince << std::endl;
std::cout << "lastModified: " << lastModified << std::endl;
if (ifModifiedSince < lastModified)
{
// If the servlet mod time is later, call doGet()
// Round down to the nearest second for a proper compare
// A ifModifiedSince of -1 will always be less
MaybeSetLastModified(response, lastModified);
DoGet(request, response);
}
else
{
response.SetStatus(HttpServletResponse::SC_NOT_MODIFIED);
}
}
}
else if (method == METHOD_HEAD)
{
long long lastModified = GetLastModified(request);
MaybeSetLastModified(response, lastModified);
DoHead(request, response);
}
else if (method == METHOD_POST)
{
DoPost(request, response);
}
else if (method == METHOD_PUT)
{
DoPut(request, response);
}
else if (method == METHOD_DELETE)
{
DoDelete(request, response);
}
// else if (method == METHOD_OPTIONS)
// {
// DoOptions(request, response);
// }
else if (method == METHOD_TRACE)
{
DoTrace(request,response);
}
else
{
//
// Note that this means NO servlet supports whatever
// method was requested, anywhere on this server.
//
std::string errMsg = std::string("Http method ") + method + " not implemented";
response.SendError(HttpServletResponse::SC_NOT_IMPLEMENTED, errMsg);
}
}