ws
Advanced tools
Comparing version 7.5.5 to 7.5.6
@@ -155,3 +155,6 @@ 'use strict'; | ||
duplex._read = function () { | ||
if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) { | ||
if ( | ||
(ws.readyState === ws.OPEN || ws.readyState === ws.CLOSING) && | ||
!resumeOnReceiverDrain | ||
) { | ||
resumeOnReceiverDrain = true; | ||
@@ -158,0 +161,0 @@ if (!ws._receiver._writableState.needDrain) ws._socket.resume(); |
@@ -621,3 +621,10 @@ /* eslint no-unused-vars: ["error", { "varsIgnorePattern": "^Readable$" }] */ | ||
if (!parsedUrl.host && (!isUnixSocket || !parsedUrl.pathname)) { | ||
throw new Error(`Invalid URL: ${websocket.url}`); | ||
const err = new Error(`Invalid URL: ${websocket.url}`); | ||
if (websocket._redirects === 0) { | ||
throw err; | ||
} else { | ||
emitErrorAndClose(websocket, err); | ||
return; | ||
} | ||
} | ||
@@ -691,5 +698,3 @@ | ||
req = websocket._req = null; | ||
websocket._readyState = WebSocket.CLOSING; | ||
websocket.emit('error', err); | ||
websocket.emitClose(); | ||
emitErrorAndClose(websocket, err); | ||
}); | ||
@@ -714,4 +719,11 @@ | ||
const addr = new URL(location, address); | ||
let addr; | ||
try { | ||
addr = new URL(location, address); | ||
} catch (err) { | ||
emitErrorAndClose(websocket, err); | ||
return; | ||
} | ||
initAsClient(websocket, addr, protocols, options); | ||
@@ -818,2 +830,15 @@ } else if (!websocket.emit('unexpected-response', req, res)) { | ||
/** | ||
* Emit the `'error'` and `'close'` event. | ||
* | ||
* @param {WebSocket} websocket The WebSocket instance | ||
* @param {Error} The error to emit | ||
* @private | ||
*/ | ||
function emitErrorAndClose(websocket, err) { | ||
websocket._readyState = WebSocket.CLOSING; | ||
websocket.emit('error', err); | ||
websocket.emitClose(); | ||
} | ||
/** | ||
* Create a `net.Socket` and initiate a connection. | ||
@@ -820,0 +845,0 @@ * |
{ | ||
"name": "ws", | ||
"version": "7.5.5", | ||
"version": "7.5.6", | ||
"description": "Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
120280
3502