mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
. Added support for 'Last-Modified' response header value and 'If-Modified-Since' request header value in the DownloadContentServlet.
- browsers can now correctly cache Alfresco content based on last-modified date of the node. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3485 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -21,6 +21,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
@@ -35,6 +36,7 @@ import org.alfresco.service.cmr.repository.ContentReader;
|
|||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.repository.StoreRef;
|
import org.alfresco.service.cmr.repository.StoreRef;
|
||||||
import org.alfresco.service.cmr.security.AccessStatus;
|
import org.alfresco.service.cmr.security.AccessStatus;
|
||||||
import org.alfresco.service.cmr.security.PermissionService;
|
import org.alfresco.service.cmr.security.PermissionService;
|
||||||
@@ -170,6 +172,7 @@ public class DownloadContentServlet extends BaseServlet
|
|||||||
|
|
||||||
// get the services we need to retrieve the content
|
// get the services we need to retrieve the content
|
||||||
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
ServiceRegistry serviceRegistry = getServiceRegistry(getServletContext());
|
||||||
|
NodeService nodeService = serviceRegistry.getNodeService();
|
||||||
ContentService contentService = serviceRegistry.getContentService();
|
ContentService contentService = serviceRegistry.getContentService();
|
||||||
PermissionService permissionService = serviceRegistry.getPermissionService();
|
PermissionService permissionService = serviceRegistry.getPermissionService();
|
||||||
|
|
||||||
@@ -184,6 +187,21 @@ public class DownloadContentServlet extends BaseServlet
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check If-Modified-Since header and set Last-Modified header as appropriate
|
||||||
|
Date modified = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
|
||||||
|
long modifiedSince = req.getDateHeader("If-Modified-Since");
|
||||||
|
if (modifiedSince > 0L)
|
||||||
|
{
|
||||||
|
// round the date to the ignore millisecond value which is not supplied by header
|
||||||
|
long modDate = (modified.getTime() / 1000L) * 1000L;
|
||||||
|
if (modDate <= modifiedSince)
|
||||||
|
{
|
||||||
|
res.setStatus(304);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res.setDateHeader("Last-Modified", modified.getTime());
|
||||||
|
|
||||||
if (attachment == true)
|
if (attachment == true)
|
||||||
{
|
{
|
||||||
// set header based on filename - will force a Save As from the browse if it doesn't recognise it
|
// set header based on filename - will force a Save As from the browse if it doesn't recognise it
|
||||||
|
Reference in New Issue
Block a user