-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: set decodeStrings to false, test
Set writableStream decodeStrings to false to let the native layer handle converting strings to buffer. PR-URL: #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>
- Loading branch information
1 parent
5622224
commit a5b6677
Showing
3 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const common = require('../common.js'); | ||
const PORT = common.PORT; | ||
|
||
var bench = common.createBenchmark(main, { | ||
streams: [100, 200, 1000], | ||
length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], | ||
}, { flags: ['--expose-http2', '--no-warnings'] }); | ||
|
||
function main(conf) { | ||
const m = +conf.streams; | ||
const l = +conf.length; | ||
const http2 = require('http2'); | ||
const server = http2.createServer(); | ||
server.on('stream', (stream) => { | ||
stream.respond(); | ||
stream.write('ü'.repeat(l)); | ||
stream.end(); | ||
}); | ||
server.listen(PORT, () => { | ||
bench.http({ | ||
path: '/', | ||
requests: 10000, | ||
maxConcurrentStreams: m, | ||
}, () => { server.close(); }); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
})); |