This commit is contained in:
Ryan 2009-03-01 12:15:27 +01:00
Родитель 2ee65b8ea2
Коммит bd136fae40
2 изменённых файлов: 22 добавлений и 46 удалений

Просмотреть файл

@ -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");
}

22
example.js Normal file
Просмотреть файл

@ -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");
}