Skip to content

Commit 2aa0405

Browse files
committed
[minor] Fix nits
1 parent 53a8888 commit 2aa0405

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

Diff for: doc/ws.md

-4
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,6 @@ This class represents a WebSocket. It extends the `EventEmitter`.
304304
`'ping'`, and `'pong'` events can be emitted multiple times in the same
305305
tick. To improve compatibility with the WHATWG standard, the default value
306306
is `false`. Setting it to `true` improves performance slightly.
307-
- `createConnection` {Function} An alternative function to use in place of
308-
`tls.createConnection` or `net.createConnection`. This can be used to
309-
manually control exactly how the connection to the server is made, or to
310-
make a connection over an existing Duplex stream obtained elsewhere.
311307
- `finishRequest` {Function} A function which can be used to customize the
312308
headers of each HTTP request before it is sent. See description below.
313309
- `followRedirects` {Boolean} Whether or not to follow redirects. Defaults to

Diff for: lib/websocket.js

-3
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,6 @@ module.exports = WebSocket;
628628
* times in the same tick
629629
* @param {Boolean} [options.autoPong=true] Specifies whether or not to
630630
* automatically send a pong in response to a ping
631-
* @param {Function} [options.createConnection] An alternative function to use
632-
* in place of `tls.createConnection` or `net.createConnection`.
633631
* @param {Function} [options.finishRequest] A function which can be used to
634632
* customize the headers of each http request before it is sent
635633
* @param {Boolean} [options.followRedirects=false] Whether or not to follow
@@ -662,7 +660,6 @@ function initAsClient(websocket, address, protocols, options) {
662660
perMessageDeflate: true,
663661
followRedirects: false,
664662
maxRedirects: 10,
665-
createConnection: undefined,
666663
...options,
667664
socketPath: undefined,
668665
hostname: undefined,

Diff for: test/websocket.test.js

+29-28
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,35 @@ describe('WebSocket', () => {
11581158
});
11591159
});
11601160

1161+
it('honors the `createConnection` option', (done) => {
1162+
const wss = new WebSocket.Server({ noServer: true, path: '/foo' });
1163+
1164+
server.once('upgrade', (req, socket, head) => {
1165+
assert.strictEqual(req.headers.host, 'google.com:22');
1166+
wss.handleUpgrade(req, socket, head, NOOP);
1167+
});
1168+
1169+
const ws = new WebSocket('ws://google.com:22/foo', {
1170+
createConnection: (options) => {
1171+
assert.strictEqual(options.host, 'google.com');
1172+
assert.strictEqual(options.port, '22');
1173+
1174+
// Ignore the `options` argument, and use the correct hostname and
1175+
// port to connect to the server.
1176+
return net.createConnection({
1177+
host: 'localhost',
1178+
port: server.address().port
1179+
});
1180+
}
1181+
});
1182+
1183+
ws.on('open', () => {
1184+
assert.strictEqual(ws.url, 'ws://google.com:22/foo');
1185+
ws.on('close', () => done());
1186+
ws.close();
1187+
});
1188+
});
1189+
11611190
it('does not follow redirects by default', (done) => {
11621191
server.once('upgrade', (req, socket) => {
11631192
socket.end(
@@ -1224,34 +1253,6 @@ describe('WebSocket', () => {
12241253
});
12251254
});
12261255

1227-
it('honors the `createConnection` option', (done) => {
1228-
const wss = new WebSocket.Server({ noServer: true, path: '/foo' });
1229-
1230-
server.once('upgrade', (req, socket, head) => {
1231-
assert.strictEqual(req.headers.host, 'google.com:22');
1232-
wss.handleUpgrade(req, socket, head, NOOP);
1233-
});
1234-
1235-
const ws = new WebSocket('ws://google.com:22/foo', {
1236-
createConnection: (options) => {
1237-
assert.strictEqual(options.host, 'google.com');
1238-
assert.strictEqual(options.port, '22');
1239-
1240-
// Ignore the invalid host address, and connect to the server manually:
1241-
return net.createConnection({
1242-
host: 'localhost',
1243-
port: server.address().port
1244-
});
1245-
}
1246-
});
1247-
1248-
ws.on('open', () => {
1249-
assert.strictEqual(ws.url, 'ws://google.com:22/foo');
1250-
ws.on('close', () => done());
1251-
ws.close();
1252-
});
1253-
});
1254-
12551256
it('emits an error if the redirect URL is invalid (1/2)', (done) => {
12561257
server.once('upgrade', (req, socket) => {
12571258
socket.end('HTTP/1.1 302 Found\r\nLocation: ws://\r\n\r\n');

0 commit comments

Comments
 (0)