DispatchUtils.sendNotModified(request, response);
return true;
}
// Add mime type header
FileContent content = fileResource.getContent(language);
// If the content is hosted externally, send a redirect and be done with it
if (content.getExternalLocation() != null) {
try {
response.sendRedirect(content.getExternalLocation().toExternalForm());
} catch (IOException e) {
logger.debug("Client ignore redirect to {}", content.getExternalLocation());
}
return true;
}
String contentType = content.getMimetype();
if (contentType == null)
contentType = MediaType.APPLICATION_OCTET_STREAM;
// Set the content type
String characterEncoding = response.getCharacterEncoding();
if (StringUtils.isNotBlank(characterEncoding))
response.setContentType(contentType + "; charset=" + characterEncoding.toLowerCase());
else
response.setContentType(contentType);
// Browser caches and proxies are allowed to keep a copy
response.setHeader("Cache-Control", "public, max-age=" + revalidationTime);
// Add last modified header
response.setDateHeader("Last-Modified", ResourceUtils.getModificationDate(fileResource, language).getTime());
// Add ETag header
String eTag = ResourceUtils.getETagValue(fileResource);
response.setHeader("ETag", eTag);
// Set the Expires header
response.setDateHeader("Expires", expirationDate);
// Add content disposition header
response.setHeader("Content-Disposition", "inline; filename=" + content.getFilename());
// Add content size
response.setHeader("Content-Length", Long.toString(content.getSize()));
// Write the file back to the response
InputStream fileContents = null;
try {
fileContents = contentRepository.getContent(fileURI, language);