Changeset e29cc2e for trip-planner-front/node_modules/ws/lib
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- Location:
- trip-planner-front/node_modules/ws/lib
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/ws/lib/buffer-util.js
r59329aa re29cc2e 16 16 17 17 const target = Buffer.allocUnsafe(totalLength); 18 letoffset = 0;18 var offset = 0; 19 19 20 for ( leti = 0; i < list.length; i++) {20 for (var i = 0; i < list.length; i++) { 21 21 const buf = list[i]; 22 target.set(buf, offset);22 buf.copy(target, offset); 23 23 offset += buf.length; 24 24 } 25 26 if (offset < totalLength) return target.slice(0, offset);27 25 28 26 return target; … … 40 38 */ 41 39 function _mask(source, mask, output, offset, length) { 42 for ( leti = 0; i < length; i++) {40 for (var i = 0; i < length; i++) { 43 41 output[offset + i] = source[i] ^ mask[i & 3]; 44 42 } … … 55 53 // Required until https://github.com/nodejs/node/issues/9006 is resolved. 56 54 const length = buffer.length; 57 for ( leti = 0; i < length; i++) {55 for (var i = 0; i < length; i++) { 58 56 buffer[i] ^= mask[i & 3]; 59 57 } … … 88 86 if (Buffer.isBuffer(data)) return data; 89 87 90 letbuf;88 var buf; 91 89 92 90 if (data instanceof ArrayBuffer) { 93 91 buf = Buffer.from(data); 94 92 } else if (ArrayBuffer.isView(data)) { 95 buf = Buffer.from(data.buffer, data.byteOffset, data.byteLength);93 buf = viewToBuffer(data); 96 94 } else { 97 95 buf = Buffer.from(data); 98 96 toBuffer.readOnly = false; 97 } 98 99 return buf; 100 } 101 102 /** 103 * Converts an `ArrayBuffer` view into a buffer. 104 * 105 * @param {(DataView|TypedArray)} view The view to convert 106 * @return {Buffer} Converted view 107 * @private 108 */ 109 function viewToBuffer(view) { 110 const buf = Buffer.from(view.buffer); 111 112 if (view.byteLength !== view.buffer.byteLength) { 113 return buf.slice(view.byteOffset, view.byteOffset + view.byteLength); 99 114 } 100 115 -
trip-planner-front/node_modules/ws/lib/event-target.js
r59329aa re29cc2e 11 11 * 12 12 * @param {String} type The name of the event 13 * @param {Object} target A reference to the target to which the event was 14 * dispatched 13 * @param {Object} target A reference to the target to which the event was dispatched 15 14 */ 16 15 constructor(type, target) { … … 31 30 * 32 31 * @param {(String|Buffer|ArrayBuffer|Buffer[])} data The received data 33 * @param {WebSocket} target A reference to the target to which the event was 34 * dispatched 32 * @param {WebSocket} target A reference to the target to which the event was dispatched 35 33 */ 36 34 constructor(data, target) { … … 51 49 * Create a new `CloseEvent`. 52 50 * 53 * @param {Number} code The status code explaining why the connection is being 54 * closed 55 * @param {String} reason A human-readable string explaining why the 56 * connection is closing 57 * @param {WebSocket} target A reference to the target to which the event was 58 * dispatched 51 * @param {Number} code The status code explaining why the connection is being closed 52 * @param {String} reason A human-readable string explaining why the connection is closing 53 * @param {WebSocket} target A reference to the target to which the event was dispatched 59 54 */ 60 55 constructor(code, reason, target) { … … 77 72 * Create a new `OpenEvent`. 78 73 * 79 * @param {WebSocket} target A reference to the target to which the event was 80 * dispatched 74 * @param {WebSocket} target A reference to the target to which the event was dispatched 81 75 */ 82 76 constructor(target) { … … 96 90 * 97 91 * @param {Object} error The error that generated this event 98 * @param {WebSocket} target A reference to the target to which the event was 99 * dispatched 92 * @param {WebSocket} target A reference to the target to which the event was dispatched 100 93 */ 101 94 constructor(error, target) { … … 117 110 * Register an event listener. 118 111 * 119 * @param {String} typeA string representing the event type to listen for112 * @param {String} method A string representing the event type to listen for 120 113 * @param {Function} listener The listener to add 121 * @param {Object} [options] An options object specifies characteristics about122 * the event listener123 * @param {Boolean} [options.once=false] A `Boolean`` indicating that the124 * listener should be invoked at most once after being added. If `true`,125 * the listener would be automatically removed when invoked.126 114 * @public 127 115 */ 128 addEventListener( type, listener, options) {116 addEventListener(method, listener) { 129 117 if (typeof listener !== 'function') return; 130 118 … … 145 133 } 146 134 147 const method = options && options.once ? 'once' : 'on'; 148 149 if (type === 'message') { 135 if (method === 'message') { 150 136 onMessage._listener = listener; 151 this [method](type, onMessage);152 } else if ( type=== 'close') {137 this.on(method, onMessage); 138 } else if (method === 'close') { 153 139 onClose._listener = listener; 154 this [method](type, onClose);155 } else if ( type=== 'error') {140 this.on(method, onClose); 141 } else if (method === 'error') { 156 142 onError._listener = listener; 157 this [method](type, onError);158 } else if ( type=== 'open') {143 this.on(method, onError); 144 } else if (method === 'open') { 159 145 onOpen._listener = listener; 160 this [method](type, onOpen);146 this.on(method, onOpen); 161 147 } else { 162 this [method](type, listener);148 this.on(method, listener); 163 149 } 164 150 }, … … 167 153 * Remove an event listener. 168 154 * 169 * @param {String} typeA string representing the event type to remove155 * @param {String} method A string representing the event type to remove 170 156 * @param {Function} listener The listener to remove 171 157 * @public 172 158 */ 173 removeEventListener( type, listener) {174 const listeners = this.listeners( type);159 removeEventListener(method, listener) { 160 const listeners = this.listeners(method); 175 161 176 for ( leti = 0; i < listeners.length; i++) {162 for (var i = 0; i < listeners.length; i++) { 177 163 if (listeners[i] === listener || listeners[i]._listener === listener) { 178 this.removeListener( type, listeners[i]);164 this.removeListener(method, listeners[i]); 179 165 } 180 166 } -
trip-planner-front/node_modules/ws/lib/extension.js
r59329aa re29cc2e 35 35 */ 36 36 function push(dest, name, elem) { 37 if ( dest[name] === undefined) dest[name] = [elem];38 else dest[name] .push(elem);37 if (Object.prototype.hasOwnProperty.call(dest, name)) dest[name].push(elem); 38 else dest[name] = [elem]; 39 39 } 40 40 … … 47 47 */ 48 48 function parse(header) { 49 const offers = Object.create(null);49 const offers = {}; 50 50 51 51 if (header === undefined || header === '') return offers; 52 52 53 let params = Object.create(null); 54 let mustUnescape = false; 55 let isEscaping = false; 56 let inQuotes = false; 57 let extensionName; 58 let paramName; 59 let start = -1; 60 let end = -1; 61 let i = 0; 62 63 for (; i < header.length; i++) { 53 var params = {}; 54 var mustUnescape = false; 55 var isEscaping = false; 56 var inQuotes = false; 57 var extensionName; 58 var paramName; 59 var start = -1; 60 var end = -1; 61 62 for (var i = 0; i < header.length; i++) { 64 63 const code = header.charCodeAt(i); 65 64 … … 78 77 if (code === 0x2c) { 79 78 push(offers, name, params); 80 params = Object.create(null);79 params = {}; 81 80 } else { 82 81 extensionName = name; … … 101 100 if (code === 0x2c) { 102 101 push(offers, extensionName, params); 103 params = Object.create(null);102 params = {}; 104 103 extensionName = undefined; 105 104 } … … 148 147 149 148 if (end === -1) end = i; 150 letvalue = header.slice(start, end);149 var value = header.slice(start, end); 151 150 if (mustUnescape) { 152 151 value = value.replace(/\\/g, ''); … … 156 155 if (code === 0x2c) { 157 156 push(offers, extensionName, params); 158 params = Object.create(null);157 params = {}; 159 158 extensionName = undefined; 160 159 } … … 175 174 const token = header.slice(start, end); 176 175 if (extensionName === undefined) { 177 push(offers, token, params);176 push(offers, token, {}); 178 177 } else { 179 178 if (paramName === undefined) { … … 200 199 return Object.keys(extensions) 201 200 .map((extension) => { 202 letconfigurations = extensions[extension];201 var configurations = extensions[extension]; 203 202 if (!Array.isArray(configurations)) configurations = [configurations]; 204 203 return configurations … … 207 206 .concat( 208 207 Object.keys(params).map((k) => { 209 letvalues = params[k];208 var values = params[k]; 210 209 if (!Array.isArray(values)) values = [values]; 211 210 return values -
trip-planner-front/node_modules/ws/lib/permessage-deflate.js
r59329aa re29cc2e 1 1 'use strict'; 2 2 3 const Limiter = require('async-limiter'); 3 4 const zlib = require('zlib'); 4 5 5 6 const bufferUtil = require('./buffer-util'); 6 const Limiter = require('./limiter');7 7 const { kStatusCode, NOOP } = require('./constants'); 8 8 9 9 const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]); 10 const EMPTY_BLOCK = Buffer.from([0x00]); 11 10 12 const kPerMessageDeflate = Symbol('permessage-deflate'); 11 13 const kTotalLength = Symbol('total-length'); … … 30 32 * Creates a PerMessageDeflate instance. 31 33 * 32 * @param {Object} [options]Configuration options33 * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept34 * disablingof server context takeover35 * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/36 * acknowledgedisabling of client context takeover37 * @param {(Boolean|Number)} [options.serverMaxWindowBits]Request/confirm the34 * @param {Object} options Configuration options 35 * @param {Boolean} options.serverNoContextTakeover Request/accept disabling 36 * of server context takeover 37 * @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge 38 * disabling of client context takeover 39 * @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the 38 40 * use of a custom server window size 39 * @param {(Boolean|Number)} [options.clientMaxWindowBits]Advertise support41 * @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support 40 42 * for, or request, a custom client window size 41 * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on 42 * deflate 43 * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on 44 * inflate 45 * @param {Number} [options.threshold=1024] Size (in bytes) below which 46 * messages should not be compressed 47 * @param {Number} [options.concurrencyLimit=10] The number of concurrent 48 * calls to zlib 49 * @param {Boolean} [isServer=false] Create the instance in either server or 50 * client mode 51 * @param {Number} [maxPayload=0] The maximum allowed message length 43 * @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate 44 * @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate 45 * @param {Number} options.threshold Size (in bytes) below which messages 46 * should not be compressed 47 * @param {Number} options.concurrencyLimit The number of concurrent calls to 48 * zlib 49 * @param {Boolean} isServer Create the instance in either server or client 50 * mode 51 * @param {Number} maxPayload The maximum allowed message length 52 52 */ 53 53 constructor(options, isServer, maxPayload) { … … 67 67 ? this._options.concurrencyLimit 68 68 : 10; 69 zlibLimiter = new Limiter( concurrency);69 zlibLimiter = new Limiter({ concurrency }); 70 70 } 71 71 } … … 134 134 135 135 if (this._deflate) { 136 const callback = this._deflate[kCallback];137 138 136 this._deflate.close(); 139 137 this._deflate = null; 140 141 if (callback) {142 callback(143 new Error(144 'The deflate stream was closed while data was being processed'145 )146 );147 }148 138 } 149 139 } … … 244 234 configurations.forEach((params) => { 245 235 Object.keys(params).forEach((key) => { 246 letvalue = params[key];236 var value = params[key]; 247 237 248 238 if (value.length > 1) { … … 295 285 296 286 /** 297 * Decompress data. Concurrency limited .287 * Decompress data. Concurrency limited by async-limiter. 298 288 * 299 289 * @param {Buffer} data Compressed data … … 303 293 */ 304 294 decompress(data, fin, callback) { 305 zlibLimiter. add((done) => {295 zlibLimiter.push((done) => { 306 296 this._decompress(data, fin, (err, result) => { 307 297 done(); … … 312 302 313 303 /** 314 * Compress data. Concurrency limited .304 * Compress data. Concurrency limited by async-limiter. 315 305 * 316 306 * @param {Buffer} data Data to compress … … 320 310 */ 321 311 compress(data, fin, callback) { 322 zlibLimiter. add((done) => {312 zlibLimiter.push((done) => { 323 313 this._compress(data, fin, (err, result) => { 324 314 done(); … … 346 336 : this.params[key]; 347 337 348 this._inflate = zlib.createInflateRaw({ 349 ...this._options.zlibInflateOptions, 350 windowBits 351 }); 338 this._inflate = zlib.createInflateRaw( 339 Object.assign({}, this._options.zlibInflateOptions, { windowBits }) 340 ); 352 341 this._inflate[kPerMessageDeflate] = this; 353 342 this._inflate[kTotalLength] = 0; … … 377 366 ); 378 367 379 if ( this._inflate._readableState.endEmitted) {368 if (fin && this.params[`${endpoint}_no_context_takeover`]) { 380 369 this._inflate.close(); 381 370 this._inflate = null; … … 383 372 this._inflate[kTotalLength] = 0; 384 373 this._inflate[kBuffers] = []; 385 386 if (fin && this.params[`${endpoint}_no_context_takeover`]) {387 this._inflate.reset();388 }389 374 } 390 375 … … 402 387 */ 403 388 _compress(data, fin, callback) { 389 if (!data || data.length === 0) { 390 process.nextTick(callback, null, EMPTY_BLOCK); 391 return; 392 } 393 404 394 const endpoint = this._isServer ? 'server' : 'client'; 405 395 … … 411 401 : this.params[key]; 412 402 413 this._deflate = zlib.createDeflateRaw({ 414 ...this._options.zlibDeflateOptions, 415 windowBits 416 }); 403 this._deflate = zlib.createDeflateRaw( 404 Object.assign({}, this._options.zlibDeflateOptions, { windowBits }) 405 ); 417 406 418 407 this._deflate[kTotalLength] = 0; … … 429 418 } 430 419 431 this._deflate[kCallback] = callback;432 433 420 this._deflate.write(data); 434 421 this._deflate.flush(zlib.Z_SYNC_FLUSH, () => { 435 422 if (!this._deflate) { 436 423 // 437 // The deflate stream was closed while data was being processed. 424 // This `if` statement is only needed for Node.js < 10.0.0 because as of 425 // commit https://github.com/nodejs/node/commit/5e3f5164, the flush 426 // callback is no longer called if the deflate stream is closed while 427 // data is being processed. 438 428 // 439 429 return; 440 430 } 441 431 442 letdata = bufferUtil.concat(432 var data = bufferUtil.concat( 443 433 this._deflate[kBuffers], 444 434 this._deflate[kTotalLength] … … 447 437 if (fin) data = data.slice(0, data.length - 4); 448 438 449 //450 // Ensure that the callback will not be called again in451 // `PerMessageDeflate#cleanup()`.452 //453 this._deflate[kCallback] = null;454 455 this._deflate[kTotalLength] = 0;456 this._deflate[kBuffers] = [];457 458 439 if (fin && this.params[`${endpoint}_no_context_takeover`]) { 459 this._deflate.reset(); 440 this._deflate.close(); 441 this._deflate = null; 442 } else { 443 this._deflate[kTotalLength] = 0; 444 this._deflate[kBuffers] = []; 460 445 } 461 446 -
trip-planner-front/node_modules/ws/lib/receiver.js
r59329aa re29cc2e 29 29 * Creates a Receiver instance. 30 30 * 31 * @param {String} [binaryType=nodebuffer] The type for binary data 32 * @param {Object} [extensions] An object containing the negotiated extensions 33 * @param {Boolean} [isServer=false] Specifies whether to operate in client or 34 * server mode 35 * @param {Number} [maxPayload=0] The maximum allowed message length 36 */ 37 constructor(binaryType, extensions, isServer, maxPayload) { 31 * @param {String} binaryType The type for binary data 32 * @param {Object} extensions An object containing the negotiated extensions 33 * @param {Number} maxPayload The maximum allowed message length 34 */ 35 constructor(binaryType, extensions, maxPayload) { 38 36 super(); 39 37 … … 41 39 this[kWebSocket] = undefined; 42 40 this._extensions = extensions || {}; 43 this._isServer = !!isServer;44 41 this._maxPayload = maxPayload | 0; 45 42 … … 69 66 * @param {String} encoding The character encoding of `chunk` 70 67 * @param {Function} cb Callback 71 * @private72 68 */ 73 69 _write(chunk, encoding, cb) { … … 101 97 do { 102 98 const buf = this._buffers[0]; 103 const offset = dst.length - n;104 99 105 100 if (n >= buf.length) { 106 dst.set(this._buffers.shift(), offset);101 this._buffers.shift().copy(dst, dst.length - n); 107 102 } else { 108 dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);103 buf.copy(dst, dst.length - n, 0, n); 109 104 this._buffers[0] = buf.slice(n); 110 105 } … … 123 118 */ 124 119 startLoop(cb) { 125 leterr;120 var err; 126 121 this._loop = true; 127 122 … … 230 225 this._masked = (buf[1] & 0x80) === 0x80; 231 226 232 if (this._isServer) {233 if (!this._masked) {234 this._loop = false;235 return error(RangeError, 'MASK must be set', true, 1002);236 }237 } else if (this._masked) {238 this._loop = false;239 return error(RangeError, 'MASK must be clear', true, 1002);240 }241 242 227 if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16; 243 228 else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64; … … 336 321 */ 337 322 getData(cb) { 338 letdata = EMPTY_BUFFER;323 var data = EMPTY_BUFFER; 339 324 340 325 if (this._payloadLength) { … … 416 401 417 402 if (this._opcode === 2) { 418 letdata;403 var data; 419 404 420 405 if (this._binaryType === 'nodebuffer') { -
trip-planner-front/node_modules/ws/lib/sender.js
r59329aa re29cc2e 1 1 'use strict'; 2 2 3 const { random FillSync} = require('crypto');3 const { randomBytes } = require('crypto'); 4 4 5 5 const PerMessageDeflate = require('./permessage-deflate'); … … 8 8 const { mask: applyMask, toBuffer } = require('./buffer-util'); 9 9 10 const mask = Buffer.alloc(4);11 12 10 /** 13 11 * HyBi Sender implementation. … … 18 16 * 19 17 * @param {net.Socket} socket The connection socket 20 * @param {Object} [extensions]An object containing the negotiated extensions18 * @param {Object} extensions An object containing the negotiated extensions 21 19 */ 22 20 constructor(socket, extensions) { … … 38 36 * @param {Object} options Options object 39 37 * @param {Number} options.opcode The opcode 40 * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be 41 * modified 42 * @param {Boolean} [options.fin=false] Specifies whether or not to set the 43 * FIN bit 44 * @param {Boolean} [options.mask=false] Specifies whether or not to mask 45 * `data` 46 * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the 47 * RSV1 bit 38 * @param {Boolean} options.readOnly Specifies whether `data` can be modified 39 * @param {Boolean} options.fin Specifies whether or not to set the FIN bit 40 * @param {Boolean} options.mask Specifies whether or not to mask `data` 41 * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit 48 42 * @return {Buffer[]} The framed data as a list of `Buffer` instances 49 43 * @public … … 51 45 static frame(data, options) { 52 46 const merge = options.mask && options.readOnly; 53 letoffset = options.mask ? 6 : 2;54 letpayloadLength = data.length;47 var offset = options.mask ? 6 : 2; 48 var payloadLength = data.length; 55 49 56 50 if (data.length >= 65536) { … … 78 72 if (!options.mask) return [target, data]; 79 73 80 randomFillSync(mask, 0,4);74 const mask = randomBytes(4); 81 75 82 76 target[1] |= 0x80; … … 98 92 * Sends a close message to the other peer. 99 93 * 100 * @param { Number} [code]The status code component of the body101 * @param {String} [data]The message component of the body102 * @param {Boolean} [mask=false]Specifies whether or not to mask the message103 * @param {Function} [cb]Callback94 * @param {(Number|undefined)} code The status code component of the body 95 * @param {String} data The message component of the body 96 * @param {Boolean} mask Specifies whether or not to mask the message 97 * @param {Function} cb Callback 104 98 * @public 105 99 */ 106 100 close(code, data, mask, cb) { 107 letbuf;101 var buf; 108 102 109 103 if (code === undefined) { … … 115 109 buf.writeUInt16BE(code, 0); 116 110 } else { 117 const length = Buffer.byteLength(data); 118 119 if (length > 123) { 120 throw new RangeError('The message must not be greater than 123 bytes'); 121 } 122 123 buf = Buffer.allocUnsafe(2 + length); 111 buf = Buffer.allocUnsafe(2 + Buffer.byteLength(data)); 124 112 buf.writeUInt16BE(code, 0); 125 113 buf.write(data, 2); … … 137 125 * 138 126 * @param {Buffer} data The message to send 139 * @param {Boolean} [mask=false]Specifies whether or not to mask `data`140 * @param {Function} [cb]Callback127 * @param {Boolean} mask Specifies whether or not to mask `data` 128 * @param {Function} cb Callback 141 129 * @private 142 130 */ … … 158 146 * 159 147 * @param {*} data The message to send 160 * @param {Boolean} [mask=false]Specifies whether or not to mask `data`161 * @param {Function} [cb]Callback148 * @param {Boolean} mask Specifies whether or not to mask `data` 149 * @param {Function} cb Callback 162 150 * @public 163 151 */ … … 165 153 const buf = toBuffer(data); 166 154 167 if (buf.length > 125) {168 throw new RangeError('The data size must not be greater than 125 bytes');169 }170 171 155 if (this._deflating) { 172 156 this.enqueue([this.doPing, buf, mask, toBuffer.readOnly, cb]); … … 179 163 * Frames and sends a ping message. 180 164 * 181 * @param { Buffer} data The message to send182 * @param {Boolean} [mask=false]Specifies whether or not to mask `data`183 * @param {Boolean} [readOnly=false]Specifies whether `data` can be modified184 * @param {Function} [cb]Callback165 * @param {*} data The message to send 166 * @param {Boolean} mask Specifies whether or not to mask `data` 167 * @param {Boolean} readOnly Specifies whether `data` can be modified 168 * @param {Function} cb Callback 185 169 * @private 186 170 */ … … 202 186 * 203 187 * @param {*} data The message to send 204 * @param {Boolean} [mask=false]Specifies whether or not to mask `data`205 * @param {Function} [cb]Callback188 * @param {Boolean} mask Specifies whether or not to mask `data` 189 * @param {Function} cb Callback 206 190 * @public 207 191 */ … … 209 193 const buf = toBuffer(data); 210 194 211 if (buf.length > 125) {212 throw new RangeError('The data size must not be greater than 125 bytes');213 }214 215 195 if (this._deflating) { 216 196 this.enqueue([this.doPong, buf, mask, toBuffer.readOnly, cb]); … … 223 203 * Frames and sends a pong message. 224 204 * 225 * @param { Buffer} data The message to send226 * @param {Boolean} [mask=false]Specifies whether or not to mask `data`227 * @param {Boolean} [readOnly=false]Specifies whether `data` can be modified228 * @param {Function} [cb]Callback205 * @param {*} data The message to send 206 * @param {Boolean} mask Specifies whether or not to mask `data` 207 * @param {Boolean} readOnly Specifies whether `data` can be modified 208 * @param {Function} cb Callback 229 209 * @private 230 210 */ … … 247 227 * @param {*} data The message to send 248 228 * @param {Object} options Options object 249 * @param {Boolean} [options.compress=false] Specifies whether or not to 250 * compress `data` 251 * @param {Boolean} [options.binary=false] Specifies whether `data` is binary 252 * or text 253 * @param {Boolean} [options.fin=false] Specifies whether the fragment is the 254 * last one 255 * @param {Boolean} [options.mask=false] Specifies whether or not to mask 256 * `data` 257 * @param {Function} [cb] Callback 229 * @param {Boolean} options.compress Specifies whether or not to compress `data` 230 * @param {Boolean} options.binary Specifies whether `data` is binary or text 231 * @param {Boolean} options.fin Specifies whether the fragment is the last one 232 * @param {Boolean} options.mask Specifies whether or not to mask `data` 233 * @param {Function} cb Callback 258 234 * @public 259 235 */ … … 261 237 const buf = toBuffer(data); 262 238 const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName]; 263 letopcode = options.binary ? 2 : 1;264 letrsv1 = options.compress;239 var opcode = options.binary ? 2 : 1; 240 var rsv1 = options.compress; 265 241 266 242 if (this._firstFragment) { … … 309 285 * 310 286 * @param {Buffer} data The message to send 311 * @param {Boolean} [compress=false] Specifies whether or not to compress 312 * `data` 287 * @param {Boolean} compress Specifies whether or not to compress `data` 313 288 * @param {Object} options Options object 314 289 * @param {Number} options.opcode The opcode 315 * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be 316 * modified 317 * @param {Boolean} [options.fin=false] Specifies whether or not to set the 318 * FIN bit 319 * @param {Boolean} [options.mask=false] Specifies whether or not to mask 320 * `data` 321 * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the 322 * RSV1 bit 323 * @param {Function} [cb] Callback 290 * @param {Boolean} options.readOnly Specifies whether `data` can be modified 291 * @param {Boolean} options.fin Specifies whether or not to set the FIN bit 292 * @param {Boolean} options.mask Specifies whether or not to mask `data` 293 * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit 294 * @param {Function} cb Callback 324 295 * @private 325 296 */ … … 332 303 const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName]; 333 304 334 this._bufferedBytes += data.length;335 305 this._deflating = true; 336 306 perMessageDeflate.compress(data, options.fin, (_, buf) => { 337 if (this._socket.destroyed) {338 const err = new Error(339 'The socket was closed while data was being compressed'340 );341 342 if (typeof cb === 'function') cb(err);343 344 for (let i = 0; i < this._queue.length; i++) {345 const callback = this._queue[i][4];346 347 if (typeof callback === 'function') callback(err);348 }349 350 return;351 }352 353 this._bufferedBytes -= data.length;354 307 this._deflating = false; 355 308 options.readOnly = false; … … 369 322 370 323 this._bufferedBytes -= params[1].length; 371 Reflect.apply(params[0],this, params.slice(1));324 params[0].apply(this, params.slice(1)); 372 325 } 373 326 } … … 388 341 * 389 342 * @param {Buffer[]} list The frame to send 390 * @param {Function} [cb]Callback343 * @param {Function} cb Callback 391 344 * @private 392 345 */ -
trip-planner-front/node_modules/ws/lib/validation.js
r59329aa re29cc2e 1 1 'use strict'; 2 3 try { 4 const isValidUTF8 = require('utf-8-validate'); 5 6 exports.isValidUTF8 = 7 typeof isValidUTF8 === 'object' 8 ? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0 9 : isValidUTF8; 10 } catch (e) /* istanbul ignore next */ { 11 exports.isValidUTF8 = () => true; 12 } 2 13 3 14 /** … … 8 19 * @public 9 20 */ 10 function isValidStatusCode(code){21 exports.isValidStatusCode = (code) => { 11 22 return ( 12 23 (code >= 1000 && 13 code <= 101 4&&24 code <= 1013 && 14 25 code !== 1004 && 15 26 code !== 1005 && … … 17 28 (code >= 3000 && code <= 4999) 18 29 ); 19 } 20 21 /** 22 * Checks if a given buffer contains only correct UTF-8. 23 * Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by 24 * Markus Kuhn. 25 * 26 * @param {Buffer} buf The buffer to check 27 * @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false` 28 * @public 29 */ 30 function _isValidUTF8(buf) { 31 const len = buf.length; 32 let i = 0; 33 34 while (i < len) { 35 if ((buf[i] & 0x80) === 0) { 36 // 0xxxxxxx 37 i++; 38 } else if ((buf[i] & 0xe0) === 0xc0) { 39 // 110xxxxx 10xxxxxx 40 if ( 41 i + 1 === len || 42 (buf[i + 1] & 0xc0) !== 0x80 || 43 (buf[i] & 0xfe) === 0xc0 // Overlong 44 ) { 45 return false; 46 } 47 48 i += 2; 49 } else if ((buf[i] & 0xf0) === 0xe0) { 50 // 1110xxxx 10xxxxxx 10xxxxxx 51 if ( 52 i + 2 >= len || 53 (buf[i + 1] & 0xc0) !== 0x80 || 54 (buf[i + 2] & 0xc0) !== 0x80 || 55 (buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // Overlong 56 (buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // Surrogate (U+D800 - U+DFFF) 57 ) { 58 return false; 59 } 60 61 i += 3; 62 } else if ((buf[i] & 0xf8) === 0xf0) { 63 // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx 64 if ( 65 i + 3 >= len || 66 (buf[i + 1] & 0xc0) !== 0x80 || 67 (buf[i + 2] & 0xc0) !== 0x80 || 68 (buf[i + 3] & 0xc0) !== 0x80 || 69 (buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // Overlong 70 (buf[i] === 0xf4 && buf[i + 1] > 0x8f) || 71 buf[i] > 0xf4 // > U+10FFFF 72 ) { 73 return false; 74 } 75 76 i += 4; 77 } else { 78 return false; 79 } 80 } 81 82 return true; 83 } 84 85 try { 86 let isValidUTF8 = require('utf-8-validate'); 87 88 /* istanbul ignore if */ 89 if (typeof isValidUTF8 === 'object') { 90 isValidUTF8 = isValidUTF8.Validation.isValidUTF8; // utf-8-validate@<3.0.0 91 } 92 93 module.exports = { 94 isValidStatusCode, 95 isValidUTF8(buf) { 96 return buf.length < 150 ? _isValidUTF8(buf) : isValidUTF8(buf); 97 } 98 }; 99 } catch (e) /* istanbul ignore next */ { 100 module.exports = { 101 isValidStatusCode, 102 isValidUTF8: _isValidUTF8 103 }; 104 } 30 }; -
trip-planner-front/node_modules/ws/lib/websocket-server.js
r59329aa re29cc2e 2 2 3 3 const EventEmitter = require('events'); 4 const { createHash }= require('crypto');5 const { createServer, STATUS_CODES }= require('http');4 const crypto = require('crypto'); 5 const http = require('http'); 6 6 7 7 const PerMessageDeflate = require('./permessage-deflate'); 8 const extension = require('./extension'); 8 9 const WebSocket = require('./websocket'); 9 const { format, parse } = require('./extension'); 10 const { GUID, kWebSocket } = require('./constants'); 10 const { GUID } = require('./constants'); 11 11 12 12 const keyRegex = /^[+/0-9A-Za-z]{22}==$/; … … 22 22 * 23 23 * @param {Object} options Configuration options 24 * @param {Number} [options.backlog=511] The maximum length of the queue of 25 * pending connections 26 * @param {Boolean} [options.clientTracking=true] Specifies whether or not to 27 * track clients 28 * @param {Function} [options.handleProtocols] A hook to handle protocols 29 * @param {String} [options.host] The hostname where to bind the server 30 * @param {Number} [options.maxPayload=104857600] The maximum allowed message 31 * size 32 * @param {Boolean} [options.noServer=false] Enable no server mode 33 * @param {String} [options.path] Accept only connections matching this path 34 * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable 24 * @param {Number} options.backlog The maximum length of the queue of pending 25 * connections 26 * @param {Boolean} options.clientTracking Specifies whether or not to track 27 * clients 28 * @param {Function} options.handleProtocols An hook to handle protocols 29 * @param {String} options.host The hostname where to bind the server 30 * @param {Number} options.maxPayload The maximum allowed message size 31 * @param {Boolean} options.noServer Enable no server mode 32 * @param {String} options.path Accept only connections matching this path 33 * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable 35 34 * permessage-deflate 36 * @param {Number} [options.port]The port where to bind the server37 * @param {http.Server} [options.server]A pre-created HTTP/S server to use38 * @param {Function} [options.verifyClient] Ahook to reject connections39 * @param {Function} [callback]A listener for the `listening` event35 * @param {Number} options.port The port where to bind the server 36 * @param {http.Server} options.server A pre-created HTTP/S server to use 37 * @param {Function} options.verifyClient An hook to reject connections 38 * @param {Function} callback A listener for the `listening` event 40 39 */ 41 40 constructor(options, callback) { 42 41 super(); 43 42 44 options = { 45 maxPayload: 100 * 1024 * 1024, 46 perMessageDeflate: false, 47 handleProtocols: null, 48 clientTracking: true, 49 verifyClient: null, 50 noServer: false, 51 backlog: null, // use default (511 as implemented in net.js) 52 server: null, 53 host: null, 54 path: null, 55 port: null, 56 ...options 57 }; 43 options = Object.assign( 44 { 45 maxPayload: 100 * 1024 * 1024, 46 perMessageDeflate: false, 47 handleProtocols: null, 48 clientTracking: true, 49 verifyClient: null, 50 noServer: false, 51 backlog: null, // use default (511 as implemented in net.js) 52 server: null, 53 host: null, 54 path: null, 55 port: null 56 }, 57 options 58 ); 58 59 59 60 if (options.port == null && !options.server && !options.noServer) { … … 64 65 65 66 if (options.port != null) { 66 this._server = createServer((req, res) => {67 const body = STATUS_CODES[426];67 this._server = http.createServer((req, res) => { 68 const body = http.STATUS_CODES[426]; 68 69 69 70 res.writeHead(426, { … … 84 85 85 86 if (this._server) { 86 const emitConnection = this.emit.bind(this, 'connection');87 88 87 this._removeListeners = addListeners(this._server, { 89 88 listening: this.emit.bind(this, 'listening'), 90 89 error: this.emit.bind(this, 'error'), 91 90 upgrade: (req, socket, head) => { 92 this.handleUpgrade(req, socket, head, emitConnection); 91 this.handleUpgrade(req, socket, head, (ws) => { 92 this.emit('connection', ws, req); 93 }); 93 94 } 94 95 }); … … 121 122 * Close the server. 122 123 * 123 * @param {Function} [cb]Callback124 * @param {Function} cb Callback 124 125 * @public 125 126 */ … … 208 209 209 210 try { 210 const offers = parse(req.headers['sec-websocket-extensions']);211 const offers = extension.parse(req.headers['sec-websocket-extensions']); 211 212 212 213 if (offers[PerMessageDeflate.extensionName]) { … … 226 227 origin: 227 228 req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`], 228 secure: !!(req. socket.authorized || req.socket.encrypted),229 secure: !!(req.connection.authorized || req.connection.encrypted), 229 230 req 230 231 }; … … 256 257 * @param {Buffer} head The first packet of the upgraded stream 257 258 * @param {Function} cb Callback 258 * @throws {Error} If called more than once with the same socket259 259 * @private 260 260 */ … … 265 265 if (!socket.readable || !socket.writable) return socket.destroy(); 266 266 267 if (socket[kWebSocket]) { 268 throw new Error( 269 'server.handleUpgrade() was called more than once with the same ' + 270 'socket, possibly due to a misconfiguration' 271 ); 272 } 273 274 const digest = createHash('sha1') 267 const digest = crypto 268 .createHash('sha1') 275 269 .update(key + GUID) 276 270 .digest('base64'); … … 284 278 285 279 const ws = new WebSocket(null); 286 letprotocol = req.headers['sec-websocket-protocol'];280 var protocol = req.headers['sec-websocket-protocol']; 287 281 288 282 if (protocol) { … … 300 294 if (protocol) { 301 295 headers.push(`Sec-WebSocket-Protocol: ${protocol}`); 302 ws. _protocol = protocol;296 ws.protocol = protocol; 303 297 } 304 298 } … … 306 300 if (extensions[PerMessageDeflate.extensionName]) { 307 301 const params = extensions[PerMessageDeflate.extensionName].params; 308 const value = format({302 const value = extension.format({ 309 303 [PerMessageDeflate.extensionName]: [params] 310 304 }); … … 328 322 } 329 323 330 cb(ws , req);324 cb(ws); 331 325 } 332 326 } … … 340 334 * @param {EventEmitter} server The event emitter 341 335 * @param {Object.<String, Function>} map The listeners to add 342 * @return {Function} A function that will remove the added listeners when 343 * called 336 * @return {Function} A function that will remove the added listeners when called 344 337 * @private 345 338 */ … … 384 377 function abortHandshake(socket, code, message, headers) { 385 378 if (socket.writable) { 386 message = message || STATUS_CODES[code]; 387 headers = { 388 Connection: 'close', 389 'Content-Type': 'text/html', 390 'Content-Length': Buffer.byteLength(message), 391 ...headers 392 }; 379 message = message || http.STATUS_CODES[code]; 380 headers = Object.assign( 381 { 382 Connection: 'close', 383 'Content-type': 'text/html', 384 'Content-Length': Buffer.byteLength(message) 385 }, 386 headers 387 ); 393 388 394 389 socket.write( 395 `HTTP/1.1 ${code} ${ STATUS_CODES[code]}\r\n` +390 `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` + 396 391 Object.keys(headers) 397 392 .map((h) => `${h}: ${headers[h]}`) -
trip-planner-front/node_modules/ws/lib/websocket.js
r59329aa re29cc2e 2 2 3 3 const EventEmitter = require('events'); 4 const crypto = require('crypto'); 4 5 const https = require('https'); 5 6 const http = require('http'); 6 7 const net = require('net'); 7 8 const tls = require('tls'); 8 const { randomBytes, createHash } = require('crypto'); 9 const { URL } = require('url'); 9 const url = require('url'); 10 10 11 11 const PerMessageDeflate = require('./permessage-deflate'); 12 const EventTarget = require('./event-target'); 13 const extension = require('./extension'); 12 14 const Receiver = require('./receiver'); 13 15 const Sender = require('./sender'); … … 20 22 NOOP 21 23 } = require('./constants'); 22 const { addEventListener, removeEventListener } = require('./event-target');23 const { format, parse } = require('./extension');24 const { toBuffer } = require('./buffer-util');25 24 26 25 const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED']; … … 37 36 * Create a new `WebSocket`. 38 37 * 39 * @param {(String|url.U RL)} address The URL to which to connect40 * @param {(String|String[])} [protocols]The subprotocols41 * @param {Object} [options]Connection options38 * @param {(String|url.Url|url.URL)} address The URL to which to connect 39 * @param {(String|String[])} protocols The subprotocols 40 * @param {Object} options Connection options 42 41 */ 43 42 constructor(address, protocols, options) { 44 43 super(); 45 44 45 this.readyState = WebSocket.CONNECTING; 46 this.protocol = ''; 47 46 48 this._binaryType = BINARY_TYPES[0]; 47 this._closeCode = 1006;48 49 this._closeFrameReceived = false; 49 50 this._closeFrameSent = false; 50 51 this._closeMessage = ''; 51 52 this._closeTimer = null; 53 this._closeCode = 1006; 52 54 this._extensions = {}; 53 this._protocol = '';54 this._readyState = WebSocket.CONNECTING;55 55 this._receiver = null; 56 56 this._sender = null; … … 58 58 59 59 if (address !== null) { 60 this._bufferedAmount = 0;61 60 this._isServer = false; 62 61 this._redirects = 0; … … 75 74 } 76 75 76 get CONNECTING() { 77 return WebSocket.CONNECTING; 78 } 79 get CLOSING() { 80 return WebSocket.CLOSING; 81 } 82 get CLOSED() { 83 return WebSocket.CLOSED; 84 } 85 get OPEN() { 86 return WebSocket.OPEN; 87 } 88 77 89 /** 78 90 * This deviates from the WHATWG interface since ws doesn't support the … … 101 113 */ 102 114 get bufferedAmount() { 103 if (!this._socket) return this._bufferedAmount; 104 105 return this._socket._writableState.length + this._sender._bufferedBytes; 115 if (!this._socket) return 0; 116 117 // 118 // `socket.bufferSize` is `undefined` if the socket is closed. 119 // 120 return (this._socket.bufferSize || 0) + this._sender._bufferedBytes; 106 121 } 107 122 … … 114 129 115 130 /** 116 * @type {String}117 */118 get protocol() {119 return this._protocol;120 }121 122 /**123 * @type {Number}124 */125 get readyState() {126 return this._readyState;127 }128 129 /**130 * @type {String}131 */132 get url() {133 return this._url;134 }135 136 /**137 131 * Set up the socket and the internal resources. 138 132 * 139 133 * @param {net.Socket} socket The network socket between the server and client 140 134 * @param {Buffer} head The first packet of the upgraded stream 141 * @param {Number} [maxPayload=0]The maximum allowed message size135 * @param {Number} maxPayload The maximum allowed message size 142 136 * @private 143 137 */ 144 138 setSocket(socket, head, maxPayload) { 145 139 const receiver = new Receiver( 146 this. binaryType,140 this._binaryType, 147 141 this._extensions, 148 this._isServer,149 142 maxPayload 150 143 ); … … 174 167 socket.on('error', socketOnError); 175 168 176 this. _readyState = WebSocket.OPEN;169 this.readyState = WebSocket.OPEN; 177 170 this.emit('open'); 178 171 } … … 184 177 */ 185 178 emitClose() { 179 this.readyState = WebSocket.CLOSED; 180 186 181 if (!this._socket) { 187 this._readyState = WebSocket.CLOSED;188 182 this.emit('close', this._closeCode, this._closeMessage); 189 183 return; … … 195 189 196 190 this._receiver.removeAllListeners(); 197 this._readyState = WebSocket.CLOSED;198 191 this.emit('close', this._closeCode, this._closeMessage); 199 192 } … … 214 207 * +---+ 215 208 * 216 * @param {Number} [code]Status code explaining why the connection is closing217 * @param {String} [data]A string explaining why the connection is closing209 * @param {Number} code Status code explaining why the connection is closing 210 * @param {String} data A string explaining why the connection is closing 218 211 * @public 219 212 */ … … 230 223 } 231 224 232 this. _readyState = WebSocket.CLOSING;225 this.readyState = WebSocket.CLOSING; 233 226 this._sender.close(code, data, !this._isServer, (err) => { 234 227 // … … 254 247 * Send a ping. 255 248 * 256 * @param {*} [data]The data to send257 * @param {Boolean} [mask]Indicates whether or not to mask `data`258 * @param {Function} [cb]Callback which is executed when the ping is sent249 * @param {*} data The data to send 250 * @param {Boolean} mask Indicates whether or not to mask `data` 251 * @param {Function} cb Callback which is executed when the ping is sent 259 252 * @public 260 253 */ 261 254 ping(data, mask, cb) { 262 if (this.readyState === WebSocket.CONNECTING) {263 throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');264 }265 266 255 if (typeof data === 'function') { 267 256 cb = data; … … 272 261 } 273 262 263 if (this.readyState !== WebSocket.OPEN) { 264 const err = new Error( 265 `WebSocket is not open: readyState ${this.readyState} ` + 266 `(${readyStates[this.readyState]})` 267 ); 268 269 if (cb) return cb(err); 270 throw err; 271 } 272 274 273 if (typeof data === 'number') data = data.toString(); 275 276 if (this.readyState !== WebSocket.OPEN) {277 sendAfterClose(this, data, cb);278 return;279 }280 281 274 if (mask === undefined) mask = !this._isServer; 282 275 this._sender.ping(data || EMPTY_BUFFER, mask, cb); … … 286 279 * Send a pong. 287 280 * 288 * @param {*} [data]The data to send289 * @param {Boolean} [mask]Indicates whether or not to mask `data`290 * @param {Function} [cb]Callback which is executed when the pong is sent281 * @param {*} data The data to send 282 * @param {Boolean} mask Indicates whether or not to mask `data` 283 * @param {Function} cb Callback which is executed when the pong is sent 291 284 * @public 292 285 */ 293 286 pong(data, mask, cb) { 294 if (this.readyState === WebSocket.CONNECTING) {295 throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');296 }297 298 287 if (typeof data === 'function') { 299 288 cb = data; … … 304 293 } 305 294 295 if (this.readyState !== WebSocket.OPEN) { 296 const err = new Error( 297 `WebSocket is not open: readyState ${this.readyState} ` + 298 `(${readyStates[this.readyState]})` 299 ); 300 301 if (cb) return cb(err); 302 throw err; 303 } 304 306 305 if (typeof data === 'number') data = data.toString(); 307 308 if (this.readyState !== WebSocket.OPEN) {309 sendAfterClose(this, data, cb);310 return;311 }312 313 306 if (mask === undefined) mask = !this._isServer; 314 307 this._sender.pong(data || EMPTY_BUFFER, mask, cb); … … 319 312 * 320 313 * @param {*} data The message to send 321 * @param {Object} [options] Options object 322 * @param {Boolean} [options.compress] Specifies whether or not to compress 323 * `data` 324 * @param {Boolean} [options.binary] Specifies whether `data` is binary or 325 * text 326 * @param {Boolean} [options.fin=true] Specifies whether the fragment is the 327 * last one 328 * @param {Boolean} [options.mask] Specifies whether or not to mask `data` 329 * @param {Function} [cb] Callback which is executed when data is written out 314 * @param {Object} options Options object 315 * @param {Boolean} options.compress Specifies whether or not to compress `data` 316 * @param {Boolean} options.binary Specifies whether `data` is binary or text 317 * @param {Boolean} options.fin Specifies whether the fragment is the last one 318 * @param {Boolean} options.mask Specifies whether or not to mask `data` 319 * @param {Function} cb Callback which is executed when data is written out 330 320 * @public 331 321 */ 332 322 send(data, options, cb) { 333 if (this.readyState === WebSocket.CONNECTING) {334 throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');335 }336 337 323 if (typeof options === 'function') { 338 324 cb = options; … … 340 326 } 341 327 328 if (this.readyState !== WebSocket.OPEN) { 329 const err = new Error( 330 `WebSocket is not open: readyState ${this.readyState} ` + 331 `(${readyStates[this.readyState]})` 332 ); 333 334 if (cb) return cb(err); 335 throw err; 336 } 337 342 338 if (typeof data === 'number') data = data.toString(); 343 339 344 if (this.readyState !== WebSocket.OPEN) { 345 sendAfterClose(this, data, cb); 346 return; 347 } 348 349 const opts = { 350 binary: typeof data !== 'string', 351 mask: !this._isServer, 352 compress: true, 353 fin: true, 354 ...options 355 }; 340 const opts = Object.assign( 341 { 342 binary: typeof data !== 'string', 343 mask: !this._isServer, 344 compress: true, 345 fin: true 346 }, 347 options 348 ); 356 349 357 350 if (!this._extensions[PerMessageDeflate.extensionName]) { … … 375 368 376 369 if (this._socket) { 377 this. _readyState = WebSocket.CLOSING;370 this.readyState = WebSocket.CLOSING; 378 371 this._socket.destroy(); 379 372 } … … 382 375 383 376 readyStates.forEach((readyState, i) => { 384 const descriptor = { enumerable: true, value: i }; 385 386 Object.defineProperty(WebSocket.prototype, readyState, descriptor); 387 Object.defineProperty(WebSocket, readyState, descriptor); 388 }); 389 390 [ 391 'binaryType', 392 'bufferedAmount', 393 'extensions', 394 'protocol', 395 'readyState', 396 'url' 397 ].forEach((property) => { 398 Object.defineProperty(WebSocket.prototype, property, { enumerable: true }); 377 WebSocket[readyState] = i; 399 378 }); 400 379 … … 405 384 ['open', 'error', 'close', 'message'].forEach((method) => { 406 385 Object.defineProperty(WebSocket.prototype, `on${method}`, { 407 configurable: true,408 enumerable: true,409 386 /** 410 387 * Return the listener of the event. … … 415 392 get() { 416 393 const listeners = this.listeners(method); 417 for ( leti = 0; i < listeners.length; i++) {394 for (var i = 0; i < listeners.length; i++) { 418 395 if (listeners[i]._listener) return listeners[i]._listener; 419 396 } … … 429 406 set(listener) { 430 407 const listeners = this.listeners(method); 431 for ( leti = 0; i < listeners.length; i++) {408 for (var i = 0; i < listeners.length; i++) { 432 409 // 433 410 // Remove only the listeners added via `addEventListener`. … … 440 417 }); 441 418 442 WebSocket.prototype.addEventListener = addEventListener;443 WebSocket.prototype.removeEventListener = removeEventListener;419 WebSocket.prototype.addEventListener = EventTarget.addEventListener; 420 WebSocket.prototype.removeEventListener = EventTarget.removeEventListener; 444 421 445 422 module.exports = WebSocket; … … 449 426 * 450 427 * @param {WebSocket} websocket The client to initialize 451 * @param {(String|url.U RL)} address The URL to which to connect452 * @param {String} [protocols]The subprotocols453 * @param {Object} [options]Connection options454 * @param {(Boolean|Object)} [options.perMessageDeflate=true]Enable/disable428 * @param {(String|url.Url|url.URL)} address The URL to which to connect 429 * @param {String} protocols The subprotocols 430 * @param {Object} options Connection options 431 * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable 455 432 * permessage-deflate 456 * @param {Number} [options.handshakeTimeout]Timeout in milliseconds for the433 * @param {Number} options.handshakeTimeout Timeout in milliseconds for the 457 434 * handshake request 458 * @param {Number} [options.protocolVersion=13] Value of the459 * `Sec-WebSocket-Version`header460 * @param {String} [options.origin]Value of the `Origin` or435 * @param {Number} options.protocolVersion Value of the `Sec-WebSocket-Version` 436 * header 437 * @param {String} options.origin Value of the `Origin` or 461 438 * `Sec-WebSocket-Origin` header 462 * @param {Number} [options.maxPayload=104857600] The maximum allowed message 463 * size 464 * @param {Boolean} [options.followRedirects=false] Whether or not to follow 465 * redirects 466 * @param {Number} [options.maxRedirects=10] The maximum number of redirects 467 * allowed 439 * @param {Number} options.maxPayload The maximum allowed message size 440 * @param {Boolean} options.followRedirects Whether or not to follow redirects 441 * @param {Number} options.maxRedirects The maximum number of redirects allowed 468 442 * @private 469 443 */ 470 444 function initAsClient(websocket, address, protocols, options) { 471 const opts = { 472 protocolVersion: protocolVersions[1], 473 maxPayload: 100 * 1024 * 1024, 474 perMessageDeflate: true, 475 followRedirects: false, 476 maxRedirects: 10, 477 ...options, 478 createConnection: undefined, 479 socketPath: undefined, 480 hostname: undefined, 481 protocol: undefined, 482 timeout: undefined, 483 method: undefined, 484 host: undefined, 485 path: undefined, 486 port: undefined 487 }; 445 const opts = Object.assign( 446 { 447 protocolVersion: protocolVersions[1], 448 maxPayload: 100 * 1024 * 1024, 449 perMessageDeflate: true, 450 followRedirects: false, 451 maxRedirects: 10 452 }, 453 options, 454 { 455 createConnection: undefined, 456 socketPath: undefined, 457 hostname: undefined, 458 protocol: undefined, 459 timeout: undefined, 460 method: undefined, 461 auth: undefined, 462 host: undefined, 463 path: undefined, 464 port: undefined 465 } 466 ); 488 467 489 468 if (!protocolVersions.includes(opts.protocolVersion)) { … … 494 473 } 495 474 496 letparsedUrl;497 498 if ( address instanceof URL) {475 var parsedUrl; 476 477 if (typeof address === 'object' && address.href !== undefined) { 499 478 parsedUrl = address; 500 websocket. _url = address.href;479 websocket.url = address.href; 501 480 } else { 502 parsedUrl = new URL(address); 503 websocket._url = address; 481 // 482 // The WHATWG URL constructor is not available on Node.js < 6.13.0 483 // 484 parsedUrl = url.URL ? new url.URL(address) : url.parse(address); 485 websocket.url = address; 504 486 } 505 487 … … 513 495 parsedUrl.protocol === 'wss:' || parsedUrl.protocol === 'https:'; 514 496 const defaultPort = isSecure ? 443 : 80; 515 const key = randomBytes(16).toString('base64');497 const key = crypto.randomBytes(16).toString('base64'); 516 498 const get = isSecure ? https.get : http.get; 517 let perMessageDeflate; 499 const path = parsedUrl.search 500 ? `${parsedUrl.pathname || '/'}${parsedUrl.search}` 501 : parsedUrl.pathname || '/'; 502 var perMessageDeflate; 518 503 519 504 opts.createConnection = isSecure ? tlsConnect : netConnect; … … 523 508 ? parsedUrl.hostname.slice(1, -1) 524 509 : parsedUrl.hostname; 525 opts.headers = { 526 'Sec-WebSocket-Version': opts.protocolVersion, 527 'Sec-WebSocket-Key': key, 528 Connection: 'Upgrade', 529 Upgrade: 'websocket', 530 ...opts.headers 531 }; 532 opts.path = parsedUrl.pathname + parsedUrl.search; 510 opts.headers = Object.assign( 511 { 512 'Sec-WebSocket-Version': opts.protocolVersion, 513 'Sec-WebSocket-Key': key, 514 Connection: 'Upgrade', 515 Upgrade: 'websocket' 516 }, 517 opts.headers 518 ); 519 opts.path = path; 533 520 opts.timeout = opts.handshakeTimeout; 534 521 … … 539 526 opts.maxPayload 540 527 ); 541 opts.headers['Sec-WebSocket-Extensions'] = format({528 opts.headers['Sec-WebSocket-Extensions'] = extension.format({ 542 529 [PerMessageDeflate.extensionName]: perMessageDeflate.offer() 543 530 }); … … 553 540 } 554 541 } 555 if (parsedUrl.username || parsedUrl.password) { 542 if (parsedUrl.auth) { 543 opts.auth = parsedUrl.auth; 544 } else if (parsedUrl.username || parsedUrl.password) { 556 545 opts.auth = `${parsedUrl.username}:${parsedUrl.password}`; 557 546 } 558 547 559 548 if (isUnixSocket) { 560 const parts = opts.path.split(':');549 const parts = path.split(':'); 561 550 562 551 opts.socketPath = parts[0]; … … 564 553 } 565 554 566 letreq = (websocket._req = get(opts));555 var req = (websocket._req = get(opts)); 567 556 568 557 if (opts.timeout) { … … 573 562 574 563 req.on('error', (err) => { 575 if ( req === null ||req.aborted) return;564 if (websocket._req.aborted) return; 576 565 577 566 req = websocket._req = null; 578 websocket. _readyState = WebSocket.CLOSING;567 websocket.readyState = WebSocket.CLOSING; 579 568 websocket.emit('error', err); 580 569 websocket.emitClose(); … … 598 587 req.abort(); 599 588 600 const addr = new URL(location, address); 589 const addr = url.URL 590 ? new url.URL(location, address) 591 : url.resolve(address, location); 601 592 602 593 initAsClient(websocket, addr, protocols, options); … … 621 612 req = websocket._req = null; 622 613 623 const digest = createHash('sha1') 614 const digest = crypto 615 .createHash('sha1') 624 616 .update(key + GUID) 625 617 .digest('base64'); … … 632 624 const serverProt = res.headers['sec-websocket-protocol']; 633 625 const protList = (protocols || '').split(/, */); 634 letprotError;626 var protError; 635 627 636 628 if (!protocols && serverProt) { … … 647 639 } 648 640 649 if (serverProt) websocket. _protocol = serverProt;641 if (serverProt) websocket.protocol = serverProt; 650 642 651 643 if (perMessageDeflate) { 652 644 try { 653 const extensions = parse(res.headers['sec-websocket-extensions']); 645 const extensions = extension.parse( 646 res.headers['sec-websocket-extensions'] 647 ); 654 648 655 649 if (extensions[PerMessageDeflate.extensionName]) { 656 650 perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]); 657 websocket._extensions[PerMessageDeflate.extensionName] = 658 perMessageDeflate; 651 websocket._extensions[ 652 PerMessageDeflate.extensionName 653 ] = perMessageDeflate; 659 654 } 660 655 } catch (err) { … … 680 675 */ 681 676 function netConnect(options) { 682 options.path = options.socketPath; 677 // 678 // Override `options.path` only if `options` is a copy of the original options 679 // object. This is always true on Node.js >= 8 but not on Node.js 6 where 680 // `options.socketPath` might be `undefined` even if the `socketPath` option 681 // was originally set. 682 // 683 if (options.protocolVersion) options.path = options.socketPath; 683 684 return net.connect(options); 684 685 } … … 693 694 function tlsConnect(options) { 694 695 options.path = undefined; 695 696 if (!options.servername && options.servername !== '') { 697 options.servername = net.isIP(options.host) ? '' : options.host; 698 } 699 696 options.servername = options.servername || options.host; 700 697 return tls.connect(options); 701 698 } … … 711 708 */ 712 709 function abortHandshake(websocket, stream, message) { 713 websocket. _readyState = WebSocket.CLOSING;710 websocket.readyState = WebSocket.CLOSING; 714 711 715 712 const err = new Error(message); … … 718 715 if (stream.setHeader) { 719 716 stream.abort(); 720 721 if (stream.socket && !stream.socket.destroyed) {722 //723 // On Node.js >= 14.3.0 `request.abort()` does not destroy the socket if724 // called after the request completed. See725 // https://github.com/websockets/ws/issues/1869.726 //727 stream.socket.destroy();728 }729 730 717 stream.once('abort', websocket.emitClose.bind(websocket)); 731 718 websocket.emit('error', err); … … 738 725 739 726 /** 740 * Handle cases where the `ping()`, `pong()`, or `send()` methods are called741 * when the `readyState` attribute is `CLOSING` or `CLOSED`.742 *743 * @param {WebSocket} websocket The WebSocket instance744 * @param {*} [data] The data to send745 * @param {Function} [cb] Callback746 * @private747 */748 function sendAfterClose(websocket, data, cb) {749 if (data) {750 const length = toBuffer(data).length;751 752 //753 // The `_bufferedAmount` property is used only when the peer is a client and754 // the opening handshake fails. Under these circumstances, in fact, the755 // `setSocket()` method is not called, so the `_socket` and `_sender`756 // properties are set to `null`.757 //758 if (websocket._socket) websocket._sender._bufferedBytes += length;759 else websocket._bufferedAmount += length;760 }761 762 if (cb) {763 const err = new Error(764 `WebSocket is not open: readyState ${websocket.readyState} ` +765 `(${readyStates[websocket.readyState]})`766 );767 cb(err);768 }769 }770 771 /**772 727 * The listener of the `Receiver` `'conclude'` event. 773 728 * … … 810 765 websocket._socket.removeListener('data', socketOnData); 811 766 812 websocket. _readyState = WebSocket.CLOSING;767 websocket.readyState = WebSocket.CLOSING; 813 768 websocket._closeCode = err[kStatusCode]; 814 769 websocket.emit('error', err); … … 869 824 this.removeListener('end', socketOnEnd); 870 825 871 websocket. _readyState = WebSocket.CLOSING;826 websocket.readyState = WebSocket.CLOSING; 872 827 873 828 // … … 920 875 const websocket = this[kWebSocket]; 921 876 922 websocket. _readyState = WebSocket.CLOSING;877 websocket.readyState = WebSocket.CLOSING; 923 878 websocket._receiver.end(); 924 879 this.end(); … … 936 891 this.on('error', NOOP); 937 892 938 if (websocket) { 939 websocket._readyState = WebSocket.CLOSING; 940 this.destroy(); 941 } 942 } 893 websocket.readyState = WebSocket.CLOSING; 894 this.destroy(); 895 }
Note:
See TracChangeset
for help on using the changeset viewer.