Fixing bug in http request default encoding.
authorAli Farhadi <a.farhadi@gmail.com>
Wed, 26 Jan 2011 07:36:45 +0000 (11:06 +0330)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 26 Jan 2011 20:18:25 +0000 (12:18 -0800)
lib/http.js
test/simple/test-http-default-encoding.js [new file with mode: 0644]

index a489705..4bf823a 100644 (file)
@@ -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 (file)
index 0000000..b2a08f1
--- /dev/null
@@ -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);
+});