mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.0 KiB
51 lines
1.0 KiB
16 years ago
|
fixed = ""
|
||
|
for (var i = 0; i < 20*1024; i++) {
|
||
|
fixed += "C";
|
||
|
}
|
||
|
stored = {};
|
||
16 years ago
|
new node.http.Server(function (req, res) {
|
||
16 years ago
|
var commands = req.uri.path.split("/");
|
||
16 years ago
|
var command = commands[1];
|
||
16 years ago
|
var body = "";
|
||
16 years ago
|
var arg = commands[2];
|
||
|
var status = 200;
|
||
|
|
||
16 years ago
|
//p(req.headers);
|
||
16 years ago
|
|
||
|
if (command == "bytes") {
|
||
|
var n = parseInt(arg, 10)
|
||
|
if (n <= 0)
|
||
|
throw "bytes called with n <= 0"
|
||
16 years ago
|
if (stored[n] === undefined) {
|
||
|
puts("create stored[n]");
|
||
|
stored[n] = "";
|
||
|
for (var i = 0; i < n; i++) {
|
||
|
stored[n] += "C"
|
||
|
}
|
||
16 years ago
|
}
|
||
16 years ago
|
body = stored[n];
|
||
16 years ago
|
|
||
|
} else if (command == "quit") {
|
||
16 years ago
|
res.connection.server.close();
|
||
16 years ago
|
body = "quitting";
|
||
|
|
||
|
} else if (command == "fixed") {
|
||
16 years ago
|
body = fixed;
|
||
16 years ago
|
|
||
16 years ago
|
} else {
|
||
|
status = 404;
|
||
|
body = "not found\n";
|
||
|
}
|
||
|
|
||
|
var content_length = body.length.toString();
|
||
|
|
||
16 years ago
|
res.sendHeader( status
|
||
16 years ago
|
, [ ["Content-Type", "text/plain"]
|
||
|
, ["Content-Length", content_length]
|
||
|
]
|
||
|
);
|
||
16 years ago
|
res.sendBody(body);
|
||
16 years ago
|
|
||
16 years ago
|
res.finish();
|
||
16 years ago
|
}).listen(8000);
|