public boolean dispatch(Request request,
Response response) throws IOException {
String path = request.getPath();
// Remember that the request path does not include the context path, so we can simply start
// looking for the asset path prefix right off the bat.
if (!path.startsWith(RequestConstants.ASSET_PATH_PREFIX)) return false;
// ClassLoaders like their paths to start with a leading slash.
String resourcePath = aliasManager.toResourcePath(path);
Resource resource = findResourceAndValidateDigest(response, resourcePath);
if (resource == null) return true;
if (!resource.exists())
{
response.sendError(HttpServletResponse.SC_NOT_FOUND, ServicesMessages
.assetDoesNotExist(resource));
return true;
}
long ifModifiedSince = 0;
try
{
ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
}
catch (IllegalArgumentException ex)
{
// Simulate the header being missing if it is poorly formatted.
ifModifiedSince = -1;
}
if (ifModifiedSince > 0)
{
long modified = resourceCache.getTimeModified(resource);
if (ifModifiedSince >= modified)
{
response.sendError(HttpServletResponse.SC_NOT_MODIFIED, "");
return true;
}
}
streamer.streamResource(resource);
return true;
}
|