Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Commit 1eec6da

Browse files
committed
http2: doc fix & test for http2.connect() optional arguments
1 parent 36cfaf9 commit 1eec6da

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

doc/api/http2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ server.on('stream', (stream, headers) => {
13881388
server.listen(80);
13891389
```
13901390

1391-
### http2.connect(authority, options, listener)
1391+
### http2.connect(authority[, options][, listener])
13921392
<!-- YAML
13931393
added: REPLACEME
13941394
-->
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const { mustCall } = require('../common');
5+
const { doesNotThrow } = require('assert');
6+
const { createServer, connect } = require('http2');
7+
8+
const server = createServer();
9+
server.listen(0, mustCall(() => {
10+
const authority = `http://localhost:${server.address().port}`;
11+
const options = {};
12+
const listener = () => mustCall();
13+
14+
const clients = new Set();
15+
doesNotThrow(() => clients.add(connect(authority)));
16+
doesNotThrow(() => clients.add(connect(authority, options)));
17+
doesNotThrow(() => clients.add(connect(authority, options, listener())));
18+
doesNotThrow(() => clients.add(connect(authority, listener())));
19+
20+
for (const client of clients) {
21+
client.once('connect', mustCall((headers) => {
22+
client.destroy();
23+
clients.delete(client);
24+
if (clients.size === 0) {
25+
server.close();
26+
}
27+
}));
28+
}
29+
}));

0 commit comments

Comments
 (0)