/** * Check a manifest cookie and update. * * <p>This routine will check and update a manifest cookie value to ensure that we are not * looping. If the incoming cookie is null, it simply initializes, othewise, it parses the cookie * and returns null if it requires a reset. * * @param incoming the cookie from the client. * @return either an updated cookie, or null if it was invalid. */ public static String updateManifestCookieValue(String incoming) { int manifestRequestCount = 0; long now = System.currentTimeMillis(); long cookieTime = now; if (MANIFEST_ERROR.equals(incoming)) { return null; } else { List<String> parts = AuraTextUtil.splitSimple(":", incoming, 2); if (parts != null && parts.size() == 2) { String count = parts.get(0); String date = parts.get(1); try { manifestRequestCount = Integer.parseInt(count); cookieTime = Long.parseLong(date); if (now - cookieTime > MAX_MANIFEST_TIME) { // // If we have gone off by more than 60 seconds, // reset everything to start the counter. // manifestRequestCount = 0; cookieTime = now; } if (manifestRequestCount >= MAX_MANIFEST_COUNT) { // We have had 5 requests in 60 seconds. bolt. return null; } } catch (NumberFormatException e) { // // Bad cookie! // This should actually be very hard to have happen, // since it requires a cookie to have a ':' in it, // and also to have unparseable numbers, so just punt // return null; } } } manifestRequestCount += 1; return manifestRequestCount + ":" + cookieTime; }