Allow stream to write on close
This commit is contained in:
parent
801fb8a614
commit
1b758ef268
@ -49,6 +49,5 @@ http.createServer(function (req, res) {
|
|||||||
, "Content-Length": content_length
|
, "Content-Length": content_length
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
res.write(body);
|
res.close(body, 'ascii');
|
||||||
res.close();
|
|
||||||
}).listen(8000);
|
}).listen(8000);
|
||||||
|
@ -47,8 +47,7 @@ var sys = require('sys'),
|
|||||||
http.createServer(function (req, res) {
|
http.createServer(function (req, res) {
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
res.write('Hello World');
|
res.close('Hello World');
|
||||||
res.close();
|
|
||||||
}, 2000);
|
}, 2000);
|
||||||
}).listen(8000);
|
}).listen(8000);
|
||||||
sys.puts('Server running at http://127.0.0.1:8000/');</pre>
|
sys.puts('Server running at http://127.0.0.1:8000/');</pre>
|
||||||
|
@ -372,7 +372,8 @@ OutgoingMessage.prototype.finish = function () {
|
|||||||
throw new Error("finish() has been renamed to close().");
|
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
|
if (this.chunkedEncoding) this._send("0\r\n\r\n"); // last chunk
|
||||||
this.finished = true;
|
this.finished = true;
|
||||||
this.flush();
|
this.flush();
|
||||||
|
@ -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.writable) {
|
||||||
if (this._writeQueueLast() != END_OF_FILE) {
|
if (this._writeQueueLast() != END_OF_FILE) {
|
||||||
this._writeQueue.push(END_OF_FILE);
|
this._writeQueue.push(END_OF_FILE);
|
||||||
|
@ -8,8 +8,7 @@ var client_got_eof = false;
|
|||||||
|
|
||||||
var server = http.createServer(function (req, res) {
|
var server = http.createServer(function (req, res) {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain"});
|
res.writeHead(200, {"Content-Type": "text/plain"});
|
||||||
res.write(body);
|
res.close(body);
|
||||||
res.close();
|
|
||||||
})
|
})
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -8,8 +8,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
["Content-Length", body.length],
|
["Content-Length", body.length],
|
||||||
["Content-Type", "text/plain"]
|
["Content-Type", "text/plain"]
|
||||||
]);
|
]);
|
||||||
res.write(body);
|
res.close(body);
|
||||||
res.close();
|
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -5,8 +5,7 @@ var UTF8_STRING = "南越国是前203年至前111年存在于岭南地区的一
|
|||||||
|
|
||||||
var server = http.createServer(function(req, res) {
|
var server = http.createServer(function(req, res) {
|
||||||
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
|
res.writeHead(200, {"Content-Type": "text/plain; charset=utf8"});
|
||||||
res.write(UTF8_STRING, 'utf8');
|
res.close(UTF8_STRING, 'utf8');
|
||||||
res.close();
|
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
@ -10,8 +10,7 @@ var server = http.createServer(function (req, res) {
|
|||||||
res.writeHead(200, { "Content-Type": "text/plain"
|
res.writeHead(200, { "Content-Type": "text/plain"
|
||||||
, "Content-Length": body.length
|
, "Content-Length": body.length
|
||||||
});
|
});
|
||||||
res.write(body);
|
res.close(body);
|
||||||
res.close();
|
|
||||||
});
|
});
|
||||||
server.listen(PORT);
|
server.listen(PORT);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user