// detect attacks.
if (response.getContentLength() < config.getMinThresholdBytes()) {
return response;
}
ImageInfo imageInfo = Sanselan.getImageInfo(response.getResponse(), uri.getPath());
boolean noExpand = "1".equals(request.getParam(PARAM_NO_EXPAND));
if (noExpand &&
imageInfo.getHeight() <= requestedHeight &&
imageInfo.getWidth() <= requestedWidth) {
// Don't do anything, since the current image fits within the bounding area.
isResizeRequested = false;
}
boolean isOversizedImage = isImageTooLarge(imageInfo);
if (isResizeRequested && isOversizedImage) {
HttpResponseBuilder rejectedResponseBuilder = new HttpResponseBuilder()
.setHttpStatusCode(HttpResponse.SC_FORBIDDEN)
.setResponseString(RESIZE_IMAGE_TOO_LARGE);
return rejectedResponseBuilder.create();
}
// Don't handle animations.
// TODO: This doesn't work as current Sanselan doesn't return accurate image counts.
// See animated GIF detection below.
if (imageInfo.getNumberOfImages() > 1 || isOversizedImage) {
return response;
}
int originalContentSize = response.getContentLength();
totalSourceImageSize.addAndGet(originalContentSize);
BufferedImage image = readImage(imageFormat, response);
if (isResizeRequested) {
int origWidth = imageInfo.getWidth();
int origHeight = imageInfo.getHeight();
int widthDelta = 0;
int heightDelta = 0;
if (requestedWidth == null || requestedHeight == null) {
// It is enough to cast only one int to double, Java will coerce all others to double