<commit_before>
/**
 * Module dependencies.
 */

var ws = require('websocket.io')
  , qs = require('querystring')
  , parse = require('url').parse
  , readFileSync = require('fs').readFileSync
  , transports = require('./transports')
  , debug = require('debug')('engine')
  , EventEmitter = require('events').EventEmitter
  , Socket = require('./socket')

/**
 * Module exports.
 */

module.exports = Server;

/**
 * Server constructor.
 *
 * @param {Object} options
 * @api public
 */

function Server (opts) {
  this.clients = {};
  this.clientsCount = 0;

  opts = opts || {};
  this.pingTimeout = opts.pingTimeout || 10000;
  this.pingInterval = opts.pingInterval || 30000;
  this.transports = opts.transports || Object.keys(transports);
  this.allowUpgrades = false !== opts.allowUpgrades;

  // initialize websocket server
  if (~this.transports.indexOf('websocket')) {
    this.ws = new ws.Server;
    this.ws.on('connection', this.onWebSocket.bind(this));
  }
};

/**
 * Inherits from EventEmitter.
 */

Server.prototype.__proto__ = EventEmitter.prototype;

/**
 * Hash of open clients.
 *
 * @api public
 */

Server.prototype.clients;

/**
 * Returns a list of available transports for upgrade given a certain transport.
 *
 * @return {Array}
 * @api public
 */

Server.prototype.upgrades = function (transport) {
  if (!this.allowUpgrades) return [];
  return transports[transport].upgradesTo || [];
};

/**
 * Verifies a request.
 *
 * @param {http.ServerRequest}
 * @return {Boolean} whether the request is valid
 * @api private
 */

Server.prototype.verify = function (req) {
  // transport check
  var transport = req.query.transport;
  if (!~this.transports.indexOf(transport)) {
    debug('unknown transport "%s"', transport);
    return false;
  }

  // sid check
  if (req.query.sid) {
    return this.clients.hasOwnProperty(req.query.sid);
  }

  return true;
};
<commit_msg>Added additional verification step: handshake is only over GET.<commit_after>
/**
 * Module dependencies.
 */

var ws = require('websocket.io')
  , qs = require('querystring')
  , parse = require('url').parse
  , readFileSync = require('fs').readFileSync
  , transports = require('./transports')
  , debug = require('debug')('engine')
  , EventEmitter = require('events').EventEmitter
  , Socket = require('./socket')

/**
 * Module exports.
 */

module.exports = Server;

/**
 * Server constructor.
 *
 * @param {Object} options
 * @api public
 */

function Server (opts) {
  this.clients = {};
  this.clientsCount = 0;

  opts = opts || {};
  this.pingTimeout = opts.pingTimeout || 10000;
  this.pingInterval = opts.pingInterval || 30000;
  this.transports = opts.transports || Object.keys(transports);
  this.allowUpgrades = false !== opts.allowUpgrades;

  // initialize websocket server
  if (~this.transports.indexOf('websocket')) {
    this.ws = new ws.Server;
    this.ws.on('connection', this.onWebSocket.bind(this));
  }
};

/**
 * Inherits from EventEmitter.
 */

Server.prototype.__proto__ = EventEmitter.prototype;

/**
 * Hash of open clients.
 *
 * @api public
 */

Server.prototype.clients;

/**
 * Returns a list of available transports for upgrade given a certain transport.
 *
 * @return {Array}
 * @api public
 */

Server.prototype.upgrades = function (transport) {
  if (!this.allowUpgrades) return [];
  return transports[transport].upgradesTo || [];
};

/**
 * Verifies a request.
 *
 * @param {http.ServerRequest}
 * @return {Boolean} whether the request is valid
 * @api private
 */

Server.prototype.verify = function (req) {
  // transport check
  var transport = req.query.transport;
  if (!~this.transports.indexOf(transport)) {
    debug('unknown transport "%s"', transport);
    return false;
  }

  // sid check
  if (req.query.sid) {
    return this.clients.hasOwnProperty(req.query.sid);
  } else {
    // handshake is GET only
    return 'GET' == req.method;
  }

  return true;
};

{'fraction_non_alphanumeric': 0.15644171779141106, 'fraction_numerical': 0.005623721881390593, 'mean_word_length': 3.523699421965318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6907588', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1222, 'n_words': 286}