Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing bug in http request's end method.

  • Loading branch information...
commit d81afcb3a6d2ee38d731dfe97e42bff8911fcddf 1 parent 5a49f96
@farhadi farhadi authored ry committed
Showing with 38 additions and 0 deletions.
  1. +1 −0  lib/http.js
  2. +37 −0 test/simple/test-http-request-end.js
View
1  lib/http.js
@@ -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;
View
37 test/simple/test-http-request-end.js
@@ -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);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.