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