diff --git a/benchmark/http_simple.js b/benchmark/http_simple.js index 4051577992..99685f78ab 100644 --- a/benchmark/http_simple.js +++ b/benchmark/http_simple.js @@ -49,6 +49,5 @@ http.createServer(function (req, res) { , "Content-Length": content_length } ); - res.write(body); - res.close(); + res.close(body, 'ascii'); }).listen(8000); diff --git a/doc/index.html b/doc/index.html index e93e036ced..7c5f81fef1 100644 --- a/doc/index.html +++ b/doc/index.html @@ -47,8 +47,7 @@ var sys = require('sys'), 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/'); diff --git a/lib/http.js b/lib/http.js index da957eaece..353c7daa79 100644 --- a/lib/http.js +++ b/lib/http.js @@ -372,7 +372,8 @@ OutgoingMessage.prototype.finish = function () { 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(); diff --git a/lib/net.js b/lib/net.js index 41f2be08c6..0e04cc45ad 100644 --- a/lib/net.js +++ b/lib/net.js @@ -713,7 +713,8 @@ Stream.prototype._shutdown = function () { }; -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); diff --git a/test/simple/test-http-1.0.js b/test/simple/test-http-1.0.js index 105acdcd8b..3a8cd0ebb8 100644 --- a/test/simple/test-http-1.0.js +++ b/test/simple/test-http-1.0.js @@ -8,8 +8,7 @@ var client_got_eof = false; 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); diff --git a/test/simple/test-http-cat.js b/test/simple/test-http-cat.js index f333b5e7d9..f270ca9278 100644 --- a/test/simple/test-http-cat.js +++ b/test/simple/test-http-cat.js @@ -8,8 +8,7 @@ var server = http.createServer(function (req, res) { ["Content-Length", body.length], ["Content-Type", "text/plain"] ]); - res.write(body); - res.close(); + res.close(body); }); server.listen(PORT); diff --git a/test/simple/test-http-chunked.js b/test/simple/test-http-chunked.js index a3395fcb9c..bb065de938 100644 --- a/test/simple/test-http-chunked.js +++ b/test/simple/test-http-chunked.js @@ -5,8 +5,7 @@ var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一 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); diff --git a/test/simple/test-http-client-race.js b/test/simple/test-http-client-race.js index 9076924b37..b9b0df4848 100644 --- a/test/simple/test-http-client-race.js +++ b/test/simple/test-http-client-race.js @@ -10,8 +10,7 @@ var server = http.createServer(function (req, res) { res.writeHead(200, { "Content-Type": "text/plain" , "Content-Length": body.length }); - res.write(body); - res.close(); + res.close(body); }); server.listen(PORT);