-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: http2 client socket operations
Refs: #14985
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
'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) => { | ||
stream.respond(); | ||
stream.end(); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = h2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request({ ':path': '/' }); | ||
|
||
req.on( | ||
'response', | ||
common.mustCall(() => { | ||
client.socket.pause(); | ||
// Force 'pause' when _handle.reading is false | ||
client.socket.emit('pause'); | ||
|
||
client.socket.resume(); | ||
// Force 'resume' when _handle.reading is true | ||
client.socket.emit('resume'); | ||
|
||
client.socket.emit('drain'); | ||
}) | ||
); | ||
req.on('data', common.mustNotCall()); | ||
|
||
req.on( | ||
'end', | ||
common.mustCall(() => { | ||
server.close(); | ||
client.destroy(); | ||
}) | ||
); | ||
|
||
// On the client, the close event must call | ||
client.on('close', common.mustCall()); | ||
req.end(); | ||
})); |