2009-05-16 12:49:33 +02:00
|
|
|
fixed = ""
|
|
|
|
for (var i = 0; i < 20*1024; i++) {
|
|
|
|
fixed += "C";
|
|
|
|
}
|
|
|
|
stored = {};
|
2009-05-18 12:44:01 +02:00
|
|
|
new node.http.Server(function (req, res) {
|
|
|
|
var commands = req.uri.split("/");
|
2009-05-15 18:11:49 +02:00
|
|
|
var command = commands[1];
|
2009-05-16 12:49:33 +02:00
|
|
|
var body = "";
|
2009-05-15 18:11:49 +02:00
|
|
|
var arg = commands[2];
|
|
|
|
var status = 200;
|
|
|
|
|
2009-05-18 19:33:05 +02:00
|
|
|
p(req.headers);
|
2009-05-15 18:11:49 +02:00
|
|
|
|
|
|
|
if (command == "bytes") {
|
|
|
|
var n = parseInt(arg, 10)
|
|
|
|
if (n <= 0)
|
|
|
|
throw "bytes called with n <= 0"
|
2009-05-16 12:49:33 +02:00
|
|
|
if (stored[n] === undefined) {
|
|
|
|
puts("create stored[n]");
|
|
|
|
stored[n] = "";
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
|
|
stored[n] += "C"
|
|
|
|
}
|
2009-05-15 18:11:49 +02:00
|
|
|
}
|
2009-05-16 12:49:33 +02:00
|
|
|
body = stored[n];
|
2009-05-15 18:11:49 +02:00
|
|
|
|
|
|
|
} else if (command == "quit") {
|
2009-05-18 12:44:01 +02:00
|
|
|
res.connection.server.close();
|
2009-05-15 22:41:36 +02:00
|
|
|
body = "quitting";
|
|
|
|
|
|
|
|
} else if (command == "fixed") {
|
2009-05-16 12:49:33 +02:00
|
|
|
body = fixed;
|
2009-05-15 22:41:36 +02:00
|
|
|
|
2009-05-15 18:11:49 +02:00
|
|
|
} else {
|
|
|
|
status = 404;
|
|
|
|
body = "not found\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
var content_length = body.length.toString();
|
|
|
|
|
2009-05-18 12:44:01 +02:00
|
|
|
res.sendHeader( status
|
2009-05-15 18:11:49 +02:00
|
|
|
, [ ["Content-Type", "text/plain"]
|
|
|
|
, ["Content-Length", content_length]
|
|
|
|
]
|
|
|
|
);
|
2009-05-18 12:44:01 +02:00
|
|
|
res.sendBody(body);
|
2009-05-15 18:11:49 +02:00
|
|
|
|
2009-05-18 12:44:01 +02:00
|
|
|
res.finish();
|
2009-05-15 18:11:49 +02:00
|
|
|
}).listen(8000);
|