2017-07-17 10:29:42 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-08-07 07:54:44 +02:00
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2017-07-17 10:29:42 -07:00
|
|
|
const assert = require('assert');
|
|
|
|
const http2 = require('http2');
|
|
|
|
|
|
|
|
const server = http2.createServer();
|
|
|
|
|
|
|
|
server.on('session', common.mustCall((session) => {
|
|
|
|
// Verify that the settings disabling push is received
|
|
|
|
session.on('remoteSettings', common.mustCall((settings) => {
|
|
|
|
assert.strictEqual(settings.enablePush, false);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
|
|
|
|
server.on('stream', common.mustCall((stream) => {
|
|
|
|
|
|
|
|
// The client has disabled push streams, so pushAllowed must be false,
|
|
|
|
// and pushStream() must throw.
|
|
|
|
assert.strictEqual(stream.pushAllowed, false);
|
|
|
|
|
2019-12-25 18:02:16 +01:00
|
|
|
assert.throws(() => {
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.pushStream({
|
|
|
|
':scheme': 'http',
|
|
|
|
':path': '/foobar',
|
|
|
|
':authority': `localhost:${server.address().port}`,
|
|
|
|
}, common.mustNotCall());
|
2017-12-08 16:41:38 -05:00
|
|
|
}, {
|
2017-07-17 10:29:42 -07:00
|
|
|
code: 'ERR_HTTP2_PUSH_DISABLED',
|
2019-12-25 18:02:16 +01:00
|
|
|
name: 'Error'
|
2017-12-08 16:41:38 -05:00
|
|
|
});
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
stream.respond({ ':status': 200 });
|
|
|
|
stream.end('test');
|
|
|
|
}));
|
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
2017-07-22 09:20:53 -07:00
|
|
|
const options = { settings: { enablePush: false } };
|
2017-07-17 10:29:42 -07:00
|
|
|
const client = http2.connect(`http://localhost:${server.address().port}`,
|
|
|
|
options);
|
|
|
|
const req = client.request({ ':path': '/' });
|
|
|
|
|
2018-01-06 19:34:27 +01:00
|
|
|
// Because push streams are disabled, this must not be called.
|
2017-07-17 10:29:42 -07:00
|
|
|
client.on('stream', common.mustNotCall());
|
|
|
|
|
|
|
|
req.resume();
|
|
|
|
req.on('end', common.mustCall(() => {
|
|
|
|
server.close();
|
2017-12-12 11:34:17 -08:00
|
|
|
client.close();
|
2017-07-17 10:29:42 -07:00
|
|
|
}));
|
|
|
|
req.end();
|
|
|
|
}));
|