HTTP delay and validate clients using javascript cookies when CPU overloaded
Problem this snippet solves: If CPU usage is over $::maxcpu (default 60%), send the client javascript that causes the client to delay a minimum of $::basedelay milliseconds (default 5000ms, i.e. 5 s...
Published Mar 18, 2015
Version 1.0CodeCentral_194
Cirrus
Joined May 05, 2019
CodeCentral_194
Cirrus
Joined May 05, 2019
Axel_Boersma
Mar 20, 2020Altostratus
Had to change the response because of errors:
<!DOCTYPE html>
<html >
<head >
<script >
function redirect() {
window.location=\"http://$location\";
}
</script >
</head >
<body onload=\"redirect()\" >
<script >
var end=Math.ceil($::basedelay*Math.random()) + $::basedelay;
var start=new Date().getTime();
for (var i=0; i < 1e7; i++) {
if ((new Date().getTime() - start) > end) {
break;
}
}
document.cookie = \"$::cookie=$::token; path=/\";
</script >
</body >
</html >
" "Content-Type" "text/html"
Mostly adding space before the > sign