update example.js
authorRyan <ry@tinyclouds.org>
Sun, 1 Mar 2009 11:15:27 +0000 (12:15 +0100)
committerRyan <ry@tinyclouds.org>
Sun, 1 Mar 2009 11:15:27 +0000 (12:15 +0100)
count-hosts.js [deleted file]
example.js [new file with mode: 0644]

diff --git a/count-hosts.js b/count-hosts.js
deleted file mode 100644 (file)
index d338606..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-function encode(i) { 
-  var string = i.toString();
-  var r = string.length.toString(16) + "\r\n" + string + "\r\n";
-  return r;
-}
-
-function Process(request) {
-
-  //
-  //  request.headers      => { "Content-Length": "123" }
-  //
-//  log("Processing " + request.path + ". method: " + request.method);
-//  log("version " + request.http_version);
-//  log("query_string " + request.query_string);
-//  log("fragment " + request.fragment);
-//  log("uri " + request.uri);
-//  log("headers: " + request.headers.toString());
-  //for(var f in request.headers) {
-    //log(f + ": " + request.headers[f]);
-  //}
-  var s  =  "";
-
-  // sends null on the last chunk.
-  request.onBody = function (chunk) {
-    if(chunk) {
-      //log( "got chunk length: " + chunk.length.toString() );
-      //this.respond(chunk.length.toString(16) + "\r\n" + evalchunk + "\r\n");
-      s +=  chunk;
-    } else {
-      this.respond(encode("hello world\n"));
-      var output = eval(s);
-      if(output) {
-        this.respond(encode(output));
-      }
-      this.respond(encode("\n"));
-      this.respond("0\r\n\r\n");
-      this.respond(null);
-    }
-  }
-
-  request.respond("HTTP/1.0 200 OK\r\n");
-  request.respond("Content-Type: text-plain\r\n");
-  request.respond("Transfer-Encoding: chunked\r\n");
-  request.respond("\r\n");
-}
-
diff --git a/example.js b/example.js
new file mode 100644 (file)
index 0000000..4befa8e
--- /dev/null
@@ -0,0 +1,22 @@
+  function encode(data) { 
+    var chunk = data.toString();
+    return chunk.length.toString(16) + "\r\n" + chunk + "\r\n";
+  }
+
+  function Process(request) {
+    // onBody sends null on the last chunk.
+    request.onBody = function (chunk) {
+      if(chunk) { 
+        this.respond(encode(chunk));
+      } else {
+        this.respond(encode("\n"));
+        this.respond("0\r\n\r\n");
+        this.respond(null); // signals end-of-request
+      }
+    }
+    request.respond("HTTP/1.0 200 OK\r\n");
+    request.respond("Content-Type: text-plain\r\n");
+    request.respond("Transfer-Encoding: chunked\r\n");
+    request.respond("\r\n");
+  }
+