public void run() {
// If there's a valid user-supplied token, use it. If not, get a random one.
String token;
if (tokenParam == null) {
token = lazyRandomToken.get();
} else if (memcache.load(new Key(TOKEN, tokenParam)) != null) {
token = tokenParam;
} else {
throw new BadRequestException("Invalid token");
}
// For safety we truncate all string fields so that an attacker can't blow out our memcache.
Map<String, Object> params = new HashMap<>();
params.put("status", status);
params.put("sleepSeconds", sleepSeconds);
params.put("mimeType", truncate(mimeType, MIMETYPE_MAX_LENGTH));
params.put("cookiesToDelete", truncate(cookiesToDelete, MAX_PARAM_REPETITION, NAME_MAX_LENGTH));
params.put(
"cookiesToAdd",
truncate(cookiesToAdd, MAX_PARAM_REPETITION, NAME_MAX_LENGTH, VALUE_MAX_LENGTH));
params.put(
"headers",
truncate(headers, MAX_PARAM_REPETITION, NAME_MAX_LENGTH, VALUE_MAX_LENGTH));
params.put("payload", truncate(payload, PAYLOAD_MAX_LENGTH));
memcache.save(new Key(STASH, token), params, STASH_EXPIRATION);
response.setPayload(tempUrlFactory.getTempUrl(token)).send();
}