Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2010-10-01 04:12:56 +0400
committerRyan Dahl <ry@tinyclouds.org>2010-10-02 03:16:00 +0400
commitfea3919d1bee7e9712aea62574d35adf0ff84027 (patch)
tree899f9d7a5a0ec2c6e05400d1388da429507fb897
parentb5dc54c6edf9bf1a84bc930ff4843cfb52893293 (diff)
Fix zero length buffer bug for http res.end()
Reported by Kadir Pekel <kadirpekel@gmail.com>
-rw-r--r--lib/http.js2
-rw-r--r--test/simple/test-zerolengthbufferbug.js41
2 files changed, 42 insertions, 1 deletions
diff --git a/lib/http.js b/lib/http.js
index 73a8d28b4eb..9447ebc12f8 100644
--- a/lib/http.js
+++ b/lib/http.js
@@ -519,7 +519,7 @@ OutgoingMessage.prototype.end = function (data, encoding) {
if (!hot) {
if (this.chunkedEncoding) {
ret = this._send('0\r\n\r\n'); // Last chunk.
- } else if (!data) {
+ } else {
// Force a flush, HACK.
ret = this._send('');
}
diff --git a/test/simple/test-zerolengthbufferbug.js b/test/simple/test-zerolengthbufferbug.js
new file mode 100644
index 00000000000..f5cc85c7083
--- /dev/null
+++ b/test/simple/test-zerolengthbufferbug.js
@@ -0,0 +1,41 @@
+// Serving up a zero-length buffer should work.
+
+var common = require("../common");
+var assert = common.assert;
+var http = require('http');
+
+var server = http.createServer(function (req, res) {
+ var buffer = new Buffer(0);
+ res.writeHead(200, {'Content-Type': 'text/html',
+ 'Content-Length': buffer.length});
+ res.end(buffer);
+});
+
+var gotResponse = false;
+var resBodySize = 0;
+
+server.listen(common.PORT, function () {
+ var client = http.createClient(common.PORT);
+
+ var req = client.request('GET', '/');
+ req.end();
+
+ req.on('response', function (res) {
+ gotResponse = true;
+
+ res.on('data', function (d) {
+ resBodySize += d.length;
+ });
+
+ res.on('end', function (d) {
+ server.close();
+ });
+ });
+});
+
+process.on('exit', function () {
+ assert.ok(gotResponse);
+ assert.equal(0, resBodySize);
+});
+
+