<commit_before>var Command  = require('./command');
var Packets  = require('../packets/index.js');
var util    = require('util');
var ClientConstants = require('../constants/client');

function ClientHandshake(clientFlags)
{
  this.handshake = null;
  this.clientFlags = clientFlags;
  Command.call(this);
}
util.inherits(ClientHandshake, Command);

ClientHandshake.prototype.start = function() {
  return ClientHandshake.prototype.handshakeInit;
};

ClientHandshake.prototype.sendSSLRequest = function(connection) {
  var sslRequest = new Packets.SSLRequest(this.clientFlags);
  connection.writePacket(sslRequest.toPacket());
};

ClientHandshake.prototype.sendCredentials = function(connection, packetIndex) {
  var handshakeResponse = new Packets.HandshakeResponse({
    flags   : this.clientFlags,
    password: <PASSWORD>,
    user    : connection.config.user,
    database: connection.config.database,
    charsetNumber: connection.config.charsetNumber,
    authPluginData1: this.handshake.authPluginData1,
    authPluginData2: this.handshake.authPluginData2,
    compress: connection.config.compress
  });
  connection.writePacket(handshakeResponse.toPacket());
};

ClientHandshake.prototype.handshakeInit = function(helloPacket, connection) {
  var command = this;

  this.on('connect', function(connArgs) {
    connection.emit('connect', connArgs);
  });
  this.on('error', function(err) {
    connection._protocolError = err;
    connection.emit('error', err);
  });
  this.handshake = Packets.Handshake.fromPacket(helloPacket);
  connection.serverCapabilityFlags = this.handshake.capabilityFlags;
  var serverSSLSupport = this.handshake.capabilityFlags & ClientConstants.SSL;

  // use compression only if requested by client and supported by server
  connection.config.compress = connection.config.compress && (this.handshake.capabilityFlags & ClientConstants.COMPRESS);

  if (connection.config.ssl) {
    if (!serverSSLSupport)
      throw new Error('Server does not support secure connnection');
    // send ssl upgrade request and immediately upgrade connection to secure
    this.clientFlags |= ClientConstants.SSL;
    this.sendSSLRequest(connection);
    connection.startTLS(function() {<commit_msg>set compression flag in handshake so it's actually used. Fixes #102<commit_after>var Command  = require('./command');
var Packets  = require('../packets/index.js');
var util    = require('util');
var ClientConstants = require('../constants/client');

function ClientHandshake(clientFlags)
{
  this.handshake = null;
  this.clientFlags = clientFlags;
  Command.call(this);
}
util.inherits(ClientHandshake, Command);

ClientHandshake.prototype.start = function() {
  return ClientHandshake.prototype.handshakeInit;
};

ClientHandshake.prototype.sendSSLRequest = function(connection) {
  var sslRequest = new Packets.SSLRequest(this.clientFlags);
  connection.writePacket(sslRequest.toPacket());
};

ClientHandshake.prototype.sendCredentials = function(connection, packetIndex) {
  var handshakeResponse = new Packets.HandshakeResponse({
    flags   : this.clientFlags,
    password: <PASSWORD>.config.password,
    user    : connection.config.user,
    database: connection.config.database,
    charsetNumber: connection.config.charsetNumber,
    authPluginData1: this.handshake.authPluginData1,
    authPluginData2: this.handshake.authPluginData2,
    compress: connection.config.compress
  });
  connection.writePacket(handshakeResponse.toPacket());
};

ClientHandshake.prototype.handshakeInit = function(helloPacket, connection) {
  var command = this;

  this.on('connect', function(connArgs) {
    connection.emit('connect', connArgs);
  });
  this.on('error', function(err) {
    connection._protocolError = err;
    connection.emit('error', err);
  });
  this.handshake = Packets.Handshake.fromPacket(helloPacket);
  connection.serverCapabilityFlags = this.handshake.capabilityFlags;
  var serverSSLSupport = this.handshake.capabilityFlags & ClientConstants.SSL;

  // use compression only if requested by client and supported by server
  connection.config.compress = connection.config.compress && (this.handshake.capabilityFlags & ClientConstants.COMPRESS);
  this.clientFlags = this.clientFlags | connection.config.compress;

  if (connection.config.ssl) {
    if (!serverSSLSupport)
      throw new Error('Server does not support secure connnection');
    // send ssl upgrade request and immediately upgrade connection to secure
    this.clientFlags |= ClientConstants.SSL;
    this.sendSSLRequest(connection);
    connection.startTLS(function() {
{'fraction_non_alphanumeric': 0.11329833770778652, 'fraction_numerical': 0.002405949256342957, 'mean_word_length': 5.040951122853369, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5979689', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1249, 'n_words': 255}