Ignore:
Timestamp:
11/25/21 22:08:24 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
8d391a1
Parents:
59329aa
Message:

primeNG components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/node_modules/ws/lib/websocket-server.js

    r59329aa re29cc2e  
    22
    33const EventEmitter = require('events');
    4 const { createHash } = require('crypto');
    5 const { createServer, STATUS_CODES } = require('http');
     4const crypto = require('crypto');
     5const http = require('http');
    66
    77const PerMessageDeflate = require('./permessage-deflate');
     8const extension = require('./extension');
    89const WebSocket = require('./websocket');
    9 const { format, parse } = require('./extension');
    10 const { GUID, kWebSocket } = require('./constants');
     10const { GUID } = require('./constants');
    1111
    1212const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
     
    2222   *
    2323   * @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
    3534   *     permessage-deflate
    36    * @param {Number} [options.port] The port where to bind the server
    37    * @param {http.Server} [options.server] A pre-created HTTP/S server to use
    38    * @param {Function} [options.verifyClient] A hook to reject connections
    39    * @param {Function} [callback] A listener for the `listening` event
     35   * @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
    4039   */
    4140  constructor(options, callback) {
    4241    super();
    4342
    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    );
    5859
    5960    if (options.port == null && !options.server && !options.noServer) {
     
    6465
    6566    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];
    6869
    6970        res.writeHead(426, {
     
    8485
    8586    if (this._server) {
    86       const emitConnection = this.emit.bind(this, 'connection');
    87 
    8887      this._removeListeners = addListeners(this._server, {
    8988        listening: this.emit.bind(this, 'listening'),
    9089        error: this.emit.bind(this, 'error'),
    9190        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          });
    9394        }
    9495      });
     
    121122   * Close the server.
    122123   *
    123    * @param {Function} [cb] Callback
     124   * @param {Function} cb Callback
    124125   * @public
    125126   */
     
    208209
    209210      try {
    210         const offers = parse(req.headers['sec-websocket-extensions']);
     211        const offers = extension.parse(req.headers['sec-websocket-extensions']);
    211212
    212213        if (offers[PerMessageDeflate.extensionName]) {
     
    226227        origin:
    227228          req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
    228         secure: !!(req.socket.authorized || req.socket.encrypted),
     229        secure: !!(req.connection.authorized || req.connection.encrypted),
    229230        req
    230231      };
     
    256257   * @param {Buffer} head The first packet of the upgraded stream
    257258   * @param {Function} cb Callback
    258    * @throws {Error} If called more than once with the same socket
    259259   * @private
    260260   */
     
    265265    if (!socket.readable || !socket.writable) return socket.destroy();
    266266
    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')
    275269      .update(key + GUID)
    276270      .digest('base64');
     
    284278
    285279    const ws = new WebSocket(null);
    286     let protocol = req.headers['sec-websocket-protocol'];
     280    var protocol = req.headers['sec-websocket-protocol'];
    287281
    288282    if (protocol) {
     
    300294      if (protocol) {
    301295        headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
    302         ws._protocol = protocol;
     296        ws.protocol = protocol;
    303297      }
    304298    }
     
    306300    if (extensions[PerMessageDeflate.extensionName]) {
    307301      const params = extensions[PerMessageDeflate.extensionName].params;
    308       const value = format({
     302      const value = extension.format({
    309303        [PerMessageDeflate.extensionName]: [params]
    310304      });
     
    328322    }
    329323
    330     cb(ws, req);
     324    cb(ws);
    331325  }
    332326}
     
    340334 * @param {EventEmitter} server The event emitter
    341335 * @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
    344337 * @private
    345338 */
     
    384377function abortHandshake(socket, code, message, headers) {
    385378  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    );
    393388
    394389    socket.write(
    395       `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
     390      `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r\n` +
    396391        Object.keys(headers)
    397392          .map((h) => `${h}: ${headers[h]}`)
Note: See TracChangeset for help on using the changeset viewer.