Remove include() add node.mixin()
[platform/upstream/nodejs.git] / benchmark / http_simple.js
1 libDir = node.path.join(node.path.dirname(__filename), "../lib");
2 node.libraryPaths.unshift(libDir);
3
4 node.mixin(require("/utils.js"));
5 http = require("/http.js");
6
7 fixed = ""
8 for (var i = 0; i < 20*1024; i++) {
9   fixed += "C";
10 }
11 stored = {};
12 http.createServer(function (req, res) {
13   var commands = req.uri.path.split("/");
14   var command = commands[1];
15   var body = "";
16   var arg = commands[2];
17   var status = 200;
18
19   p(req.uri.params);
20
21   if (command == "bytes") {
22     var n = parseInt(arg, 10)
23     if (n <= 0)
24       throw "bytes called with n <= 0" 
25     if (stored[n] === undefined) {
26       puts("create stored[n]");
27       stored[n] = "";
28       for (var i = 0; i < n; i++) {
29         stored[n] += "C"
30       }
31     }
32     body = stored[n];
33
34   } else if (command == "quit") {
35     res.connection.server.close();
36     body = "quitting";
37
38   } else if (command == "fixed") {
39     body = fixed;
40
41   } else {
42     status = 404;
43     body = "not found\n";
44   }
45
46   var content_length = body.length.toString();
47
48   res.sendHeader( status 
49                 , { "Content-Type": "text/plain"
50                   , "Content-Length": content_length
51                   }
52                 );
53   res.sendBody(body);
54           
55   res.finish();
56 }).listen(8000);