From 36ef5643c3a3dc1a43e80ede442d4d1cd29b6a68 Mon Sep 17 00:00:00 2001 From: Ali Farhadi Date: Wed, 26 Jan 2011 11:06:45 +0330 Subject: [PATCH] Fixing bug in http request default encoding. --- lib/http.js | 2 -- test/simple/test-http-default-encoding.js | 40 +++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 test/simple/test-http-default-encoding.js diff --git a/lib/http.js b/lib/http.js index a4897050e3..4bf823a312 100644 --- a/lib/http.js +++ b/lib/http.js @@ -380,7 +380,6 @@ OutgoingMessage.prototype._buffer = function(data, encoding) { if (length === 0 || typeof data != 'string') { this.output.push(data); - encoding = encoding || 'ascii'; this.outputEncodings.push(encoding); return false; } @@ -395,7 +394,6 @@ OutgoingMessage.prototype._buffer = function(data, encoding) { } this.output.push(data); - encoding = encoding || 'ascii'; this.outputEncodings.push(encoding); return false; diff --git a/test/simple/test-http-default-encoding.js b/test/simple/test-http-default-encoding.js new file mode 100644 index 0000000000..b2a08f1988 --- /dev/null +++ b/test/simple/test-http-default-encoding.js @@ -0,0 +1,40 @@ +var common = require('../common'); +var assert = require('assert'); +var http = require('http'); + +var expected = 'This is a unicode text: سلام'; +var result = ''; + +var server = http.Server(function(req, res) { + req.setEncoding('utf8'); + req.on('data', function(chunk) { + result += chunk; + }).on('end', function() { + clearTimeout(timeout); + server.close(); + }); + + var timeout = setTimeout(function() { + process.exit(1); + }, 100); + + 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); +});