<commit_before>const EventEmitter = require('events');
const http   = require('http');
const https  = require('https');
const HttpUtil = require('./http.js');
const HttpOptions = require('./options.js');
const Auth = require('./auth.js');
const Formatter = require('./formatter.js');
const HttpResponse = require('./response.js');
const Utils = require('./../utils');
const {Logger} = Utils;

let __defaultSettings__ = {
  credentials: null,
  use_ssl: false,
  proxy: null,
  timeout: 60000,
  retry_attempts: 0
};

let __globalSettings__ = null;

class HttpRequest extends EventEmitter {
  static get USER_AGENT() {
    const version = require('../../package.json').version;
    const platform = ({darwin: 'mac', win32: 'windows'}[process.platform]) || 'linux';

    return `nightwatch.js/${version} (${platform})`;
  }

  constructor(opts) {
    super();

    this.__settings = null;
    this.isAborted = false;
    this.httpRequest = null;
    this.httpResponse = null;
    this.retryCount = 0;
    this.addtOpts = opts.addtOpts || {};

    this.setHttpOpts();
    this.setOptions(opts);
  }

  static set globalSettings(val) {
    __globalSettings__ = val;
  }

  static get globalSettings() {
    return __globalSettings__ || HttpOptions.global.settings;
  }

  setHttpOpts() {
    this.__settings = Object.assign({}, __defaultSettings__, HttpRequest.globalSettings);
  }

  get httpOpts() {
    return this.__settings;
  }

  get socket() {
    return this.httpRequest.socket;
  }

  get elapsedTime() {
    return this.httpResponse.elapsedTime;
  }

  get statusCode() {
    return this.httpResponse.res.statusCode;
  }

  setOptions(options) {
    this.setPathPrefix(options);

    const {method} = options;
    if (options.data && !(method === 'POST' || method === 'PUT')) {
      options.data = '';
    }

    this.params = options.data;
    this.setData(options);
    this.contentLength = this.data.length;
    this.use_ssl = this.httpOpts.use_ssl || options.use_ssl;
    this.reqOptions = this.createHttpOptions(options);
    this.hostname = Formatter.formatHostname(this.reqOptions.host, this.reqOptions.port, this.use_ssl);
    this.retryAttempts = this.httpOpts.retry_attempts;
    this.redact = options.redact || false;

    return this;
  }

  setData(options) {
    if (!options.data) {
      this.data = '';

      return this;
    }

    this.data = Formatter.jsonStringify(options.data) || '';;

    return this;
  }

  setPathPrefix(options) {
    let pathContainsPrefix = options.path && options.path.includes(this.httpOpts.default_path);
    this.defaultPathPrefix = pathContainsPrefix ? '' : this.httpOpts.default_path;

    return this;
  }

  createHttpOptions(options) {
    const reqOptions = {
      path: this.defaultPathPrefix + (options.path || ''),<commit_msg>updated request.js<commit_after>const EventEmitter = require('events');
const http   = require('http');
const https  = require('https');
const HttpUtil = require('./http.js');
const HttpOptions = require('./options.js');
const Auth = require('./auth.js');
const Formatter = require('./formatter.js');
const HttpResponse = require('./response.js');
const Utils = require('./../utils');
const {Logger} = Utils;

let __defaultSettings__ = {
  credentials: null,
  use_ssl: false,
  proxy: null,
  timeout: 60000,
  retry_attempts: 0
};

let __globalSettings__ = null;

class HttpRequest extends EventEmitter {
  static get USER_AGENT() {
    const version = require('../../package.json').version;
    const platform = ({darwin: 'mac', win32: 'windows'}[process.platform]) || 'linux';

    return `nightwatch.js/${version} (${platform})`;
  }

  constructor(opts) {
    super();

    this.__settings = null;
    this.isAborted = false;
    this.httpRequest = null;
    this.httpResponse = null;
    this.retryCount = 0;
    this.addtOpts = opts.addtOpts || {};

    this.setHttpOpts();
    this.setOptions(opts);
  }

  static set globalSettings(val) {
    __globalSettings__ = val;
  }

  static get globalSettings() {
    return __globalSettings__ || HttpOptions.global.settings;
  }

  setHttpOpts() {
    this.__settings = Object.assign({}, __defaultSettings__, HttpRequest.globalSettings);
  }

  get httpOpts() {
    return this.__settings;
  }

  get socket() {
    return this.httpRequest.socket;
  }

  get elapsedTime() {
    return this.httpResponse.elapsedTime;
  }

  get statusCode() {
    return this.httpResponse.res.statusCode;
  }

  setOptions(options) {
    this.setPathPrefix(options);

    const {method} = options;
    if (options.data && !(method === 'POST' || method === 'PUT')) {
      options.data = '';
    }

    this.params = options.data;
    this.setData(options);
    this.contentLength = this.data.length;
    this.use_ssl = this.httpOpts.use_ssl || options.use_ssl;
    this.reqOptions = this.createHttpOptions(options);
    this.hostname = Formatter.formatHostname(this.reqOptions.host, this.reqOptions.port, this.use_ssl);
    this.retryAttempts = this.httpOpts.retry_attempts;
    this.redact = options.redact || false;

    return this;
  }

  setData(options) {
    if (!options.data) {
      this.data = '';

      return this;
    }

    this.data = Formatter.jsonStringify(options.data) || '';

    return this;
  }

  setPathPrefix(options) {
    let pathContainsPrefix = options.path && options.path.includes(this.httpOpts.default_path);
    this.defaultPathPrefix = pathContainsPrefix ? '' : this.httpOpts.default_path;

    return this;
  }

  createHttpOptions(options) {
    const reqOptions = {
      path: this.defaultPathPrefix + (options.path || ''),
{'fraction_non_alphanumeric': 0.14479799785484448, 'fraction_numerical': 0.0032177332856632105, 'mean_word_length': 3.444003177124702, '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': '6771973', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1750, 'n_words': 345}