Fixing bug in http request's end method.
authorAli Farhadi <a.farhadi@gmail.com>
Sun, 23 Jan 2011 21:43:59 +0000 (01:13 +0330)
committerRyan Dahl <ry@tinyclouds.org>
Sun, 23 Jan 2011 23:22:42 +0000 (15:22 -0800)
lib/http.js
test/simple/test-http-request-end.js [new file with mode: 0644]

index eb8beb1..70adece 100644 (file)
@@ -565,6 +565,7 @@ OutgoingMessage.prototype.end = function(data, encoding) {
             typeof(data) === 'string' &&
             data.length > 0 &&
             this.output.length === 0 &&
+            this.connection &&
             this.connection.writable &&
             this.connection._httpMessage === this;
 
diff --git a/test/simple/test-http-request-end.js b/test/simple/test-http-request-end.js
new file mode 100644 (file)
index 0000000..ce9bbd1
--- /dev/null
@@ -0,0 +1,37 @@
+var common = require('../common');
+var assert = require('assert');
+var http = require('http');
+
+var expected = 'Post Body For Test';
+var result = '';
+
+var server = http.Server(function(req, res) {
+  req.setEncoding('utf8');
+  req.on('data', function(chunk) {
+    result += chunk;
+  });
+
+  req.on('end', function() {
+    server.close();
+  });
+
+  res.writeHead(200);
+  res.end("hello world\n");
+});
+
+server.listen(common.PORT, function() {
+  http.request({
+    port: common.PORT,
+    path: '/',
+    method: 'POST'
+  }, function(res) {
+    console.log(res.statusCode);
+  }).on('error', function(e) {
+    console.log(e.message);
+    process.exit(1);
+  }).end(expected);
+});
+
+process.on('exit', function() {
+  assert.equal(expected, result);
+});