2017-11-15 10:55:31 -08:00
|
|
|
'use strict';
|
2017-12-11 03:56:41 -02:00
|
|
|
// Flags: --expose-internals
|
2017-11-15 10:55:31 -08:00
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
|
|
|
|
2020-07-20 15:59:36 -07:00
|
|
|
const assert = require('assert');
|
2017-11-15 10:55:31 -08:00
|
|
|
const http = require('http');
|
|
|
|
const http2 = require('http2');
|
2017-12-11 03:56:41 -02:00
|
|
|
const { NghttpError } = require('internal/http2/util');
|
2017-11-15 10:55:31 -08:00
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
// Creating an http1 server here...
|
2023-06-24 16:16:07 +02:00
|
|
|
const server = http.createServer(common.mustNotCall())
|
2021-04-07 21:04:06 -07:00
|
|
|
.on('clientError', common.mustCall((error, socket) => {
|
|
|
|
assert.strictEqual(error.code, 'HPE_PAUSED_H2_UPGRADE');
|
|
|
|
assert.strictEqual(error.bytesParsed, 24);
|
|
|
|
socket.write('HTTP/1.1 400 No H2 support\r\n\r\n');
|
|
|
|
|
|
|
|
// Don't give client a chance to send a preamble.
|
|
|
|
socket.destroy();
|
|
|
|
}));
|
2017-11-15 10:55:31 -08:00
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const client = http2.connect(`http://localhost:${server.address().port}`);
|
|
|
|
|
|
|
|
const req = client.request();
|
2017-11-25 13:02:16 -08:00
|
|
|
req.on('close', common.mustCall());
|
2017-11-15 10:55:31 -08:00
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
req.on('error', common.expectsError({
|
|
|
|
code: 'ERR_HTTP2_ERROR',
|
2019-12-25 18:02:16 +01:00
|
|
|
constructor: NghttpError,
|
2017-12-12 11:34:17 -08:00
|
|
|
message: 'Protocol error'
|
|
|
|
}));
|
|
|
|
|
2017-11-15 10:55:31 -08:00
|
|
|
client.on('error', common.expectsError({
|
|
|
|
code: 'ERR_HTTP2_ERROR',
|
2019-12-25 18:02:16 +01:00
|
|
|
constructor: NghttpError,
|
2019-03-16 12:09:14 +01:00
|
|
|
name: 'Error',
|
2017-11-15 10:55:31 -08:00
|
|
|
message: 'Protocol error'
|
|
|
|
}));
|
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
client.on('close', common.mustCall(() => server.close()));
|
2017-11-15 10:55:31 -08:00
|
|
|
}));
|