summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-04-29 20:59:44 +0200
committerAnna Henningsen <anna@addaleax.net>2017-05-03 15:31:49 +0200
commit55c95b1644f2bc2c066a60b4930de25de0e69771 (patch)
tree0fa41b52b2f57f883e76d57ba40ed0830adbbb23 /test
parent2bf461e6f502b1135f66ceff96f79152eccf1dc7 (diff)
downloadandroid-node-v8-55c95b1644f2bc2c066a60b4930de25de0e69771.tar.gz
android-node-v8-55c95b1644f2bc2c066a60b4930de25de0e69771.tar.bz2
android-node-v8-55c95b1644f2bc2c066a60b4930de25de0e69771.zip
http: fix first body chunk fast case for UTF-16
`http.OutgoingMessage` tried to send the first chunk together with the headers by concatenating them together as a string, but the list of encodings for which that works was incorrect. Change it from a blacklist to a whitelist. Fixes: https://github.com/nodejs/node/issues/11788 PR-URL: https://github.com/nodejs/node/pull/12747 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-http-outgoing-first-chunk-singlebyte-encoding.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/parallel/test-http-outgoing-first-chunk-singlebyte-encoding.js b/test/parallel/test-http-outgoing-first-chunk-singlebyte-encoding.js
new file mode 100644
index 0000000000..214287a6ff
--- /dev/null
+++ b/test/parallel/test-http-outgoing-first-chunk-singlebyte-encoding.js
@@ -0,0 +1,36 @@
+'use strict';
+const common = require('../common');
+
+// Regression test for https://github.com/nodejs/node/issues/11788.
+
+const assert = require('assert');
+const http = require('http');
+const net = require('net');
+
+for (const enc of ['utf8', 'utf16le', 'latin1', 'UTF-8']) {
+ const server = http.createServer(common.mustCall((req, res) => {
+ res.setHeader('content-type', `text/plain; charset=${enc}`);
+ res.write('helloworld', enc);
+ res.end();
+ })).listen(0);
+
+ server.on('listening', common.mustCall(() => {
+ const buffers = [];
+ const socket = net.connect(server.address().port);
+ socket.write('GET / HTTP/1.0\r\n\r\n');
+ socket.on('data', (data) => buffers.push(data));
+ socket.on('end', common.mustCall(() => {
+ const received = Buffer.concat(buffers);
+ const headerEnd = received.indexOf('\r\n\r\n', 'utf8');
+ assert.notStrictEqual(headerEnd, -1);
+
+ const header = received.toString('utf8', 0, headerEnd).split(/\r\n/g);
+ const body = received.toString(enc, headerEnd + 4);
+
+ assert.strictEqual(header[0], 'HTTP/1.1 200 OK');
+ assert.strictEqual(header[1], `content-type: text/plain; charset=${enc}`);
+ assert.strictEqual(body, 'helloworld');
+ server.close();
+ }));
+ }));
+}