summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-createwritereq.js
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2017-09-07 13:20:37 -0400
committerJames M Snell <jasnell@gmail.com>2017-09-07 16:05:37 -0700
commit2ffc8ac3017eb2246deb99019aacd618e5c088c3 (patch)
tree831c71e79d6cc1fef8808262350c28da2348fa49 /test/parallel/test-http2-createwritereq.js
parent91dc50726ba61e447a2f3d7f9ef108ded95d2f64 (diff)
downloadandroid-node-v8-2ffc8ac3017eb2246deb99019aacd618e5c088c3.tar.gz
android-node-v8-2ffc8ac3017eb2246deb99019aacd618e5c088c3.tar.bz2
android-node-v8-2ffc8ac3017eb2246deb99019aacd618e5c088c3.zip
http2: set decodeStrings to false, test
Set writableStream decodeStrings to false to let the native layer handle converting strings to buffer. PR-URL: https://github.com/nodejs/node/pull/15140 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-http2-createwritereq.js')
-rw-r--r--test/parallel/test-http2-createwritereq.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/parallel/test-http2-createwritereq.js b/test/parallel/test-http2-createwritereq.js
new file mode 100644
index 0000000000..7e4bd5cf11
--- /dev/null
+++ b/test/parallel/test-http2-createwritereq.js
@@ -0,0 +1,68 @@
+// Flags: --expose-http2
+'use strict';
+
+const common = require('../common');
+if (!common.hasCrypto)
+ common.skip('missing crypto');
+const assert = require('assert');
+const http2 = require('http2');
+
+// Tests that write uses the correct encoding when writing
+// using the helper function createWriteReq
+
+const testString = 'a\u00A1\u0100\uD83D\uDE00';
+
+const encodings = {
+ 'buffer': 'utf8',
+ 'ascii': 'ascii',
+ 'latin1': 'latin1',
+ 'binary': 'latin1',
+ 'utf8': 'utf8',
+ 'utf-8': 'utf8',
+ 'ucs2': 'ucs2',
+ 'ucs-2': 'ucs2',
+ 'utf16le': 'ucs2',
+ 'utf-16le': 'ucs2',
+ 'UTF8': 'utf8' // should fall through to Buffer.from
+};
+
+const testsToRun = Object.keys(encodings).length;
+let testsFinished = 0;
+
+const server = http2.createServer(common.mustCall((req, res) => {
+ const testEncoding = encodings[req.path.slice(1)];
+
+ req.on('data', common.mustCall((chunk) => assert.ok(
+ Buffer.from(testString, testEncoding).equals(chunk)
+ )));
+
+ req.on('end', () => res.end());
+}, Object.keys(encodings).length));
+
+server.listen(0, common.mustCall(function() {
+ Object.keys(encodings).forEach((writeEncoding) => {
+ const client = http2.connect(`http://localhost:${this.address().port}`);
+ const req = client.request({
+ ':path': `/${writeEncoding}`,
+ ':method': 'POST'
+ });
+
+ assert.strictEqual(req._writableState.decodeStrings, false);
+ req.write(
+ writeEncoding !== 'buffer' ? testString : Buffer.from(testString),
+ writeEncoding !== 'buffer' ? writeEncoding : undefined
+ );
+ req.resume();
+
+ req.on('end', common.mustCall(function() {
+ client.destroy();
+ testsFinished++;
+
+ if (testsFinished === testsToRun) {
+ server.close();
+ }
+ }));
+
+ req.end();
+ });
+}));