2017-10-19 21:32:20 -04:00
|
|
|
// Flags: --expose-internals
|
|
|
|
|
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 h2 = require('http2');
|
2017-10-19 21:32:20 -04:00
|
|
|
const { kSocket } = require('internal/http2/util');
|
|
|
|
|
2017-07-17 10:29:42 -07:00
|
|
|
const body =
|
|
|
|
'<html><head></head><body><h1>this is some data</h2></body></html>';
|
|
|
|
|
|
|
|
const server = h2.createServer();
|
|
|
|
|
2019-03-07 01:03:53 +01:00
|
|
|
// We use the lower-level API here
|
2017-12-12 11:34:17 -08:00
|
|
|
server.on('stream', common.mustCall((stream) => {
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.on('aborted', common.mustCall());
|
2017-12-12 11:34:17 -08:00
|
|
|
stream.on('close', common.mustCall());
|
|
|
|
stream.respond();
|
2017-07-17 10:29:42 -07:00
|
|
|
stream.write(body);
|
2019-03-22 03:44:26 +01:00
|
|
|
// Purposefully do not end()
|
2017-12-12 11:34:17 -08:00
|
|
|
}));
|
2017-07-17 10:29:42 -07:00
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
server.listen(0, common.mustCall(function() {
|
2017-07-17 10:29:42 -07:00
|
|
|
const client = h2.connect(`http://localhost:${this.address().port}`);
|
2017-12-12 11:34:17 -08:00
|
|
|
const req = client.request();
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
req.on('response', common.mustCall(() => {
|
2019-03-22 03:44:26 +01:00
|
|
|
// Send a premature socket close
|
2017-10-19 21:32:20 -04:00
|
|
|
client[kSocket].destroy();
|
2017-07-17 10:29:42 -07:00
|
|
|
}));
|
|
|
|
|
2017-12-12 11:34:17 -08:00
|
|
|
req.resume();
|
|
|
|
req.on('end', common.mustCall());
|
|
|
|
req.on('close', common.mustCall(() => server.close()));
|
2017-07-17 10:29:42 -07:00
|
|
|
|
|
|
|
// On the client, the close event must call
|
|
|
|
client.on('close', common.mustCall());
|
|
|
|
}));
|