PortalRequestHandler extends WebRequestHandler { public String getSanitizedCacheControl(String cacheControl) { if (null == cacheControl) { return null; } return CACHE_CONTROL_SANITIZE_PATTERN.matcher(cacheControl).replaceAll(""); }  String getHandlerName(); @Override void onInit(WebAppController controller, ServletConfig sConfig); @SuppressWarnings("unchecked") @Override boolean execute(ControllerContext controllerContext); String getSanitizedCacheControl(String cacheControl); static final QualifiedName REQUEST_PATH; static final QualifiedName REQUEST_SITE_TYPE; static final QualifiedName REQUEST_SITE_NAME; static final QualifiedName LANG; }
@Test public void testDoNotUrlEncodeCacheControl() { PortalRequestHandler handler = new PortalRequestHandler(); String cacheControl = "no-cache, max-age=0, must-revalidate, no-store"; assertEquals(cacheControl, handler.getSanitizedCacheControl(cacheControl)); }
@Test public void testPreventResponseSplitting() { PortalRequestHandler handler = new PortalRequestHandler(); String expected = "Wiley HackerHTTP/1.1 200 OK"; String cacheControl = "Wiley Hacker\r\n\r\nHTTP/1.1 200 OK\r\n"; assertEquals(expected, handler.getSanitizedCacheControl(cacheControl)); cacheControl = "Wiley Hacker\r\rHTTP/1.1 200 OK\r"; assertEquals(expected, handler.getSanitizedCacheControl(cacheControl)); cacheControl = "Wiley Hacker\rHTTP/1.1 200 OK\r"; assertEquals(expected, handler.getSanitizedCacheControl(cacheControl)); cacheControl = "Wiley Hacker\nHTTP/1.1 200 OK\n"; assertEquals(expected, handler.getSanitizedCacheControl(cacheControl)); }