2009-02-23 22:43:50 +01:00
|
|
|
function encode(i) {
|
|
|
|
var string = i.toString();
|
|
|
|
var r = string.length.toString(16) + "\r\n" + string + "\r\n";
|
|
|
|
return r;
|
|
|
|
}
|
2009-02-23 21:04:30 +01:00
|
|
|
|
2009-02-20 17:06:07 +01:00
|
|
|
function Process(request) {
|
2009-02-23 21:04:30 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// request.headers => { "Content-Length": "123" }
|
|
|
|
//
|
2009-02-24 19:13:58 +01:00
|
|
|
// 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]);
|
|
|
|
//}
|
2009-02-23 22:43:50 +01:00
|
|
|
var s = "";
|
2009-02-21 21:00:40 +01:00
|
|
|
|
2009-02-22 18:15:18 +01:00
|
|
|
// sends null on the last chunk.
|
2009-02-21 21:00:40 +01:00
|
|
|
request.onBody = function (chunk) {
|
2009-02-23 21:04:30 +01:00
|
|
|
if(chunk) {
|
2009-02-23 21:53:03 +01:00
|
|
|
//log( "got chunk length: " + chunk.length.toString() );
|
2009-02-23 22:43:50 +01:00
|
|
|
//this.respond(chunk.length.toString(16) + "\r\n" + evalchunk + "\r\n");
|
|
|
|
s += chunk;
|
2009-02-23 21:04:30 +01:00
|
|
|
} else {
|
2009-02-24 19:13:58 +01:00
|
|
|
this.respond(encode("hello world\n"));
|
2009-02-23 22:43:50 +01:00
|
|
|
var output = eval(s);
|
2009-02-24 19:13:58 +01:00
|
|
|
if(output) {
|
|
|
|
this.respond(encode(output));
|
|
|
|
}
|
2009-02-23 22:43:50 +01:00
|
|
|
this.respond(encode("\n"));
|
2009-02-23 21:04:30 +01:00
|
|
|
this.respond("0\r\n\r\n");
|
|
|
|
this.respond(null);
|
|
|
|
}
|
2009-02-20 17:06:07 +01:00
|
|
|
}
|
2009-02-22 18:15:18 +01:00
|
|
|
|
2009-02-23 21:04:30 +01:00
|
|
|
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");
|
2009-02-20 17:06:07 +01:00
|
|
|
}
|
2009-02-23 21:04:30 +01:00
|
|
|
|