<commit_before>'use strict';

const http = require('http');
const url = require('url');
const uws = require('uws');

/**
 * Server of µWebSockets transformer.
 *
 * @runat server
 * @api private
 */
module.exports = function server() {
  const options = this.primus.options;
  const maxLength = options.transport.maxPayload || options.maxLength;
  let mask = 0;

  if (options.compression || options.transport.perMessageDeflate) {
    mask = uws.PERMESSAGE_DEFLATE;
    if (options.transport.perMessageDeflate) {
      if (options.transport.perMessageDeflate.serverNoContextTakeover) {
        mask |= uws.SERVER_NO_CONTEXT_TAKEOVER;
      }
      if (options.transport.perMessageDeflate.clientNoContextTakeover) {
        mask |= uws.CLIENT_NO_CONTEXT_TAKEOVER;
      }
    }
  }

  this.service = new uws.uws.Server(0, mask, maxLength);

  this.service.onMessage((socket, msg, binary, spark) => {
    spark.emit('incoming::data', binary ? msg : msg.toString());
  });

  this.service.onDisconnection((socket, code, msg, spark) => {
    this.service.setData(socket);
    spark.ultron.remove('outgoing::end');
    spark.emit('incoming::end');
  });

  //
  // Listen to upgrade requests.
  //
  this.on('upgrade', (req, soc, head) => {
    const secKey = req.headers['sec-websocket-key'];
    let ticket;

    if (secKey && secKey.length === 24) {
      soc.setNoDelay(options.transport.noDelay);
      ticket = this.service.transfer(
        soc._handle.fd === -1 ? soc._handle : soc._handle.fd,
        soc.ssl ? soc.ssl._external : null
      );
<commit_msg>[fix] Fix SSL connection transfer in the uws transformer<commit_after>'use strict';

const http = require('http');
const url = require('url');
const uws = require('uws');

/**
 * Server of µWebSockets transformer.
 *
 * @runat server
 * @api private
 */
module.exports = function server() {
  const options = this.primus.options;
  const maxLength = options.transport.maxPayload || options.maxLength;
  let mask = 0;

  if (options.compression || options.transport.perMessageDeflate) {
    mask = uws.PERMESSAGE_DEFLATE;
    if (options.transport.perMessageDeflate) {
      if (options.transport.perMessageDeflate.serverNoContextTakeover) {
        mask |= uws.SERVER_NO_CONTEXT_TAKEOVER;
      }
      if (options.transport.perMessageDeflate.clientNoContextTakeover) {
        mask |= uws.CLIENT_NO_CONTEXT_TAKEOVER;
      }
    }
  }

  this.service = new uws.uws.Server(0, mask, maxLength);

  this.service.onMessage((socket, msg, binary, spark) => {
    spark.emit('incoming::data', binary ? msg : msg.toString());
  });

  this.service.onDisconnection((socket, code, msg, spark) => {
    this.service.setData(socket);
    spark.ultron.remove('outgoing::end');
    spark.emit('incoming::end');
  });

  //
  // Listen to upgrade requests.
  //
  this.on('upgrade', (req, soc) => {
    const secKey = req.headers['sec-websocket-key'];

    if (secKey && secKey.length === 24) {
      soc.setNoDelay(options.transport.noDelay);

      let socketHandle = soc._handle;
      let sslState = null;

      if (soc.ssl) {
        socketHandle = soc._parent._handle;
        sslState = soc.ssl._external;
      }

      const ticket = this.service.transfer(
        socketHandle.fd === -1 ? socketHandle : socketHandle.fd,
        sslState
      );

{'fraction_non_alphanumeric': 0.14462934947049924, 'fraction_numerical': 0.0030257186081694403, 'mean_word_length': 3.1954314720812182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3486218', 'n_tokens_mistral': 1081, 'n_tokens_neox': 1047, 'n_words': 204}