This also notably changes error handling for request(). Previously some invalid header values (but not all) would cause the session to be unnecessarily destroyed automatically, e.g. passing an unparseable header name to request(). This is no longer the case: header validation failures will throw an error, but will not destroy the session or emit 'error' events. PR-URL: https://github.com/nodejs/node/pull/57917 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
const assert = require('assert');
|
|
const http2 = require('http2');
|
|
|
|
{
|
|
const server = http2.createServer();
|
|
server.on('stream', common.mustCall((stream, headers, flags, rawHeaders) => {
|
|
assert.deepStrictEqual(rawHeaders, [
|
|
':path', '/foobar',
|
|
':scheme', 'http',
|
|
':authority', `localhost:${server.address().port}`,
|
|
':method', 'GET',
|
|
'a', 'b',
|
|
'x-foo', 'bar',
|
|
'a', 'c',
|
|
]);
|
|
stream.respond({
|
|
':status': 200
|
|
});
|
|
stream.end();
|
|
}));
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const port = server.address().port;
|
|
const client = http2.connect(`http://localhost:${port}`);
|
|
|
|
const req = client.request([
|
|
':path', '/foobar',
|
|
':scheme', 'http',
|
|
':authority', `localhost:${server.address().port}`,
|
|
':method', 'GET',
|
|
'a', 'b',
|
|
'x-FOO', 'bar',
|
|
'a', 'c',
|
|
]).end();
|
|
|
|
req.on('response', common.mustCall((headers) => {
|
|
assert.strictEqual(headers[':status'], 200);
|
|
client.close();
|
|
server.close();
|
|
}));
|
|
}));
|
|
}
|