@ Override public void handleRequest ( final Request request ) { super . handleRequest ( request ) ; String targ = request . getParameter ( Environment . TARGET_ID ) ; boolean contentReqested = ( targ != null && targ . equals ( getTargetId ( ) ) ) ; if ( contentReqested ) { ContentEscape escape = new ContentEscape ( getImage ( ) ) ; escape . setCacheable ( ! Util . empty ( getCacheKey ( ) ) ) ; throw escape ; } }
When an img element is included in the html output of a page the browser will make a second request to get the image contents . The handleRequest method has been overridden to detect whether the request is the image content fetch request by looking for the parameter that we encode in the image url .