Skip to content

Commit

Permalink
Allow stream to write on close
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Apr 5, 2010
1 parent 801fb8a commit 1b758ef
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 14 deletions.
3 changes: 1 addition & 2 deletions benchmark/http_simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ http.createServer(function (req, res) {
, "Content-Length": content_length
}
);
res.write(body);
res.close();
res.close(body, 'ascii');
}).listen(8000);
3 changes: 1 addition & 2 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
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>
Expand Down
3 changes: 2 additions & 1 deletion lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions test/simple/test-http-1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions test/simple/test-http-cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions test/simple/test-http-chunked.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions test/simple/test-http-client-race.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 1b758ef

Please sign in to comment.