0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 14:33:11 +01:00
nodejs/example.js

27 lines
685 B
JavaScript
Raw Normal View History

function encode(data) {
var chunk = data.toString();
return chunk.length.toString(16) + "\r\n" + chunk + "\r\n";
}
function Process(request) {
log( "path: " + request.path );
log( "query string: " + request.query_string );
2009-03-01 12:15:27 +01:00
// 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
2009-03-01 12:15:27 +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-03-01 12:15:27 +01:00