<commit_before>
var sys = require("sys")
  , events = require("events")
  , Buffer = require("buffer").Buffer
  , Crypto = require("crypto");


/*-----------------------------------------------
  Debugged
-----------------------------------------------*/
var debug;

/*-----------------------------------------------
  The Connection:
-----------------------------------------------*/
module.exports = Connection;

function Connection(server, req, socket, upgradeHead){
  this.debug = server.debug;
  
  if (this.debug) {
    debug = function () { sys.error('\033[90mWS: ' + Array.prototype.join.call(arguments, ", ") + "\033[39m"); };
  } else {
    debug = function () { };
  }
  
  this._req = req;
  this._server = server;
  this._upgradeHead = upgradeHead;
  this._id = this._req.socket.remotePort;
  
  events.EventEmitter.call(this);
  
  this.version = this.getVersion();
  
  if( !checkVersion(this)) {
    this.reject("Invalid version.");
  } else {
    debug(this._id, this.version+" connection");
    
    // Set the initial connecting state.
    this.state(1);
    
    // Allow us to send data immediately:
    req.socket.setNoDelay(true);
    
    // Hopefully allow us to keep the socket open indefinitely:
    req.socket.setTimeout(0);
    req.socket.setKeepAlive(true, 0);
    
    // Handle incoming data:
    var parser = new Parser(this);
    req.socket.addListener("data", function(data){
      parser.write(data);
    });
    
    // Handle the end of the stream, and set the state 
    // appropriately to notify the correct events.
    var connection = this;
    req.socket.addListener("end", function(){
      connection.state(5);
    });
    
    // Setup the connection manager's state change listeners:
    this.addListener("stateChange", function(state, oldstate){
      if(state == 5){
        server.manager.detach(connection._id, function(){
          server.emit("close", connection);
          connection.emit("close");<commit_msg>Modifying the connection data handler to support the broken header use case.<commit_after>
var sys = require("sys")
  , events = require("events")
  , Buffer = require("buffer").Buffer
  , Crypto = require("crypto");


/*-----------------------------------------------
  Debugged
-----------------------------------------------*/
var debug;

/*-----------------------------------------------
  The Connection:
-----------------------------------------------*/
module.exports = Connection;

function Connection(server, req, socket, upgradeHead){
  this.debug = server.debug;
  
  if (this.debug) {
    debug = function () { sys.error('\033[90mWS: ' + Array.prototype.join.call(arguments, ", ") + "\033[39m"); };
  } else {
    debug = function () { };
  }
  
  this._req = req;
  this._server = server;
  this._upgradeHead = upgradeHead;
  this._id = this._req.socket.remotePort;
  
  events.EventEmitter.call(this);
  
  this.version = this.getVersion();
  
  if( !checkVersion(this)) {
    this.reject("Invalid version.");
  } else {
    debug(this._id, this.version+" connection");
    
    // Set the initial connecting state.
    this.state(1);
    
    // Allow us to send data immediately:
    req.socket.setNoDelay(true);
    
    // Hopefully allow us to keep the socket open indefinitely:
    req.socket.setTimeout(0);
    req.socket.setKeepAlive(true, 0);
    
    var connection = this;
    // Handle incoming data:
    var parser = new Parser(this);
    req.socket.addListener("data", function(data){
      if(connection._state == 2){
        connection._upgradeHead = data;
      } else {
        parser.write(data);
      }
    });
    
    // Handle the end of the stream, and set the state 
    // appropriately to notify the correct events.
    req.socket.addListener("end", function(){
      connection.state(5);
    });
    
    // Setup the connection manager's state change listeners:
    this.addListener("stateChange", function(state, oldstate){
      if(state == 5){
        server.manager.detach(connection._id, function(){
          server.emit("close", connection);
          connection.emit("close");
{'fraction_non_alphanumeric': 0.2215437225207621, 'fraction_numerical': 0.007572056668295066, 'mean_word_length': 2.0400890868596884, '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': '2444560', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1119, 'n_words': 269}