mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

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>
81 lines
1.9 KiB
JavaScript
81 lines
1.9 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
if (!common.hasCrypto) { common.skip('missing crypto'); }
|
|
|
|
// Check for:
|
|
// Spaced headers
|
|
// Pseudo headers
|
|
// Capitalized headers
|
|
|
|
const http2 = require('http2');
|
|
const { throws } = require('assert');
|
|
|
|
{
|
|
const server = http2.createServer(common.mustCall((req, res) => {
|
|
throws(() => {
|
|
res.setHeader(':path', '/');
|
|
}, {
|
|
code: 'ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED'
|
|
});
|
|
throws(() => {
|
|
res.setHeader('t est', 123);
|
|
}, {
|
|
code: 'ERR_INVALID_HTTP_TOKEN'
|
|
});
|
|
res.setHeader('TEST', 123);
|
|
res.setHeader('test_', 123);
|
|
res.setHeader(' test', 123);
|
|
res.end();
|
|
}));
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
const session = http2.connect(`http://localhost:${server.address().port}`);
|
|
session.request({ 'test_': 123, 'TEST': 123 })
|
|
.on('end', common.mustCall(() => {
|
|
session.close();
|
|
server.close();
|
|
}));
|
|
}));
|
|
}
|
|
|
|
{
|
|
const server = http2.createServer();
|
|
server.listen(0, common.mustCall(() => {
|
|
const session = http2.connect(`http://localhost:${server.address().port}`);
|
|
throws(() => {
|
|
session.request({ 't est': 123 });
|
|
}, {
|
|
code: 'ERR_INVALID_HTTP_TOKEN'
|
|
});
|
|
session.close();
|
|
server.close();
|
|
}));
|
|
}
|
|
|
|
{
|
|
const server = http2.createServer();
|
|
server.listen(0, common.mustCall(() => {
|
|
const session = http2.connect(`http://localhost:${server.address().port}`);
|
|
throws(() => {
|
|
session.request({ ' test': 123 });
|
|
}, {
|
|
code: 'ERR_INVALID_HTTP_TOKEN'
|
|
});
|
|
session.close();
|
|
server.close();
|
|
}));
|
|
}
|
|
|
|
{
|
|
const server = http2.createServer();
|
|
server.listen(0, common.mustCall(() => {
|
|
const session = http2.connect(`http://localhost:${server.address().port}`);
|
|
throws(() => {
|
|
session.request({ ':test': 123 });
|
|
}, {
|
|
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER'
|
|
});
|
|
session.close();
|
|
server.close();
|
|
}));
|
|
}
|