Skip to content

Instantly share code, notes, and snippets.

@NimJay
Created June 12, 2020 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NimJay/b2ccb19360cc043c472b24c4e6008df2 to your computer and use it in GitHub Desktop.
Save NimJay/b2ccb19360cc043c472b24c4e6008df2 to your computer and use it in GitHub Desktop.
This bit of JavaScript can be used to repeatedly make an HTTP request to an endpoint.
/**
* This script could be used to test whether an endpoint could handle an overload
* of HTTP requests.
*/
{
const URL = "https://example.com";
const MILLISEC_WAIT_PER_REQUEST = 100;
function bombardWithHttpRequest() {
fetch(URL)
.then(function(response) {
return response.json();
});
return delay(MILLISEC_WAIT_PER_REQUEST)
.then(ddos);
}
function delay(ms) {
return new Promise((res, rej) => {
setTimeout(res, ms);
});
}
// bombardWithHttpRequest();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment