node/test/parallel/test-http2-misused-pseudoheaders.js
Brian White 8f6ab9f799
Revert "stream: prevent 'end' to be emitted after 'error'"
This reverts commit 0857790656.

PR-URL: https://github.com/nodejs/node/pull/20449
Fixes: https://github.com/nodejs/node/issues/20334
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-05-07 09:44:26 +02:00

50 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');
const server = h2.createServer();
server.on('stream', common.mustCall((stream) => {
[
':path',
':authority',
':method',
':scheme'
].forEach((i) => {
common.expectsError(() => stream.respond({ [i]: '/' }),
{
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
});
stream.respond({}, { waitForTrailers: true });
stream.on('wantTrailers', () => {
common.expectsError(() => {
stream.sendTrailers({ ':status': 'bar' });
}, {
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
});
stream.close();
});
stream.end('hello world');
}));
server.listen(0, common.mustCall(() => {
const client = h2.connect(`http://localhost:${server.address().port}`);
const req = client.request();
req.on('response', common.mustCall());
req.resume();
req.on('end', common.mustCall());
req.on('close', common.mustCall(() => {
server.close();
client.close();
}));
}));