, "Content-Length": content_length
}
);
- res.write(body);
- res.close();
+ res.close(body, 'ascii');
}).listen(8000);
http.createServer(function (req, res) {
setTimeout(function () {
res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('Hello World');
- res.close();
+ res.close('Hello World');
}, 2000);
}).listen(8000);
sys.puts('Server running at http://127.0.0.1:8000/');</pre>
throw new Error("finish() has been renamed to close().");
};
-OutgoingMessage.prototype.close = function () {
+OutgoingMessage.prototype.close = function (data, encoding) {
+ if (data) this.write(data, encoding);
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
this.finished = true;
this.flush();
};
-Stream.prototype.close = function () {
+Stream.prototype.close = function (data, encoding) {
+ if (data) this.write(data, encoding);
if (this.writable) {
if (this._writeQueueLast() != END_OF_FILE) {
this._writeQueue.push(END_OF_FILE);
var server = http.createServer(function (req, res) {
res.writeHead(200, {"Content-Type": "text/plain"});
- res.write(body);
- res.close();
+ res.close(body);
})
server.listen(PORT);
["Content-Length", body.length],
["Content-Type", "text/plain"]
]);
- res.write(body);
- res.close();
+ res.close(body);
});
server.listen(PORT);
var server = http.createServer(function(req, res) {
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
- res.write(UTF8_STRING, 'utf8');
- res.close();
+ res.close(UTF8_STRING, 'utf8');
});
server.listen(PORT);
res.writeHead(200, { "Content-Type": "text/plain"
, "Content-Length": body.length
});
- res.write(body);
- res.close();
+ res.close(body);
});
server.listen(PORT);