<commit_before>/* istanbul ignore file */

const http = require('http');
const request = require('request'); // eslint-disable-line import/no-unresolved, import/no-extraneous-dependencies

/*
 * url {String}
 * options {Object}
 * options.headers {Object}
 * options.body {String|Object}
 * options.form {Boolean}
 * options.query {Object}
 * options.timeout {Number}
 * options.retries {Number}
 * options.followRedirect {Boolean}
 */

class HTTPError extends Error {
  constructor(response) {
    const statusMessage = http.STATUS_CODES[response.statusCode];
    super(`Response code ${response.statusCode} (${statusMessage})`, {});
    this.name = 'HTTPError';
    this.statusCode = response.statusCode;
    this.statusMessage = statusMessage;
    this.headers = response.headers;
    this.response = response;
  }
}

function requestWrap(method, url, options) {
  if (options.form) {
    /* eslint-disable no-param-reassign */
    options.form = options.body;
    options.body = undefined;
    /* eslint-enable no-param-reassign */
  }
  return new Promise((resolve, reject) => {
    request({
      method,
      url,
      headers: options.headers,
      qs: options.query,
      body: options.body,
      form: options.form,
      followRedirect: options.followRedirect,
      timeout: options.timeout,
    }, (error, response, body) => {
      if (error) {
        reject(error);
      } else {
        response.body = body;
        const { statusCode } = response;
        const limitStatusCode = options.followRedirect ? 299 : 399;

        if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) {
          reject(new HTTPError(response));
          return;
        }

        resolve(response);
      }
    });
  });
}

module.exports = {
  get: function requestGet(url, options) {
    return requestWrap('GET', url, options);
  },
  post: function requestPost(url, options) {
    return requestWrap('POST', url, options);<commit_msg>use all httpOptions in request. fixes #282<commit_after>/* istanbul ignore file */

const http = require('http');
const request = require('request'); // eslint-disable-line import/no-unresolved, import/no-extraneous-dependencies

/*
 * url {String}
 * options {Object}
 * options.headers {Object}
 * options.body {String|Object}
 * options.form {Boolean}
 * options.query {Object}
 * options.timeout {Number}
 * options.retries {Number}
 * options.followRedirect {Boolean}
 */

class HTTPError extends Error {
  constructor(response) {
    const statusMessage = http.STATUS_CODES[response.statusCode];
    super(`Response code ${response.statusCode} (${statusMessage})`, {});
    this.name = 'HTTPError';
    this.statusCode = response.statusCode;
    this.statusMessage = statusMessage;
    this.headers = response.headers;
    this.response = response;
  }
}

function requestWrap(method, url, {
  form,
  body,
  query,
  ...options
}) {
  if (form) {
    /* eslint-disable no-param-reassign */
    form = body;
    body = undefined;
    /* eslint-enable no-param-reassign */
  }
  return new Promise((resolve, reject) => {
    request({
      ...options,
      body,
      form,
      method,
      url,
      qs: query,
    }, (error, response, responseBody) => {
      if (error) {
        reject(error);
      } else {
        response.body = responseBody;
        const { statusCode } = response;
        const limitStatusCode = options.followRedirect ? 299 : 399;

        if (statusCode !== 304 && (statusCode < 200 || statusCode > limitStatusCode)) {
          reject(new HTTPError(response));
          return;
        }

        resolve(response);
      }
    });
  });
}

module.exports = {
  get: function requestGet(url, options) {
    return requestWrap('GET', url, options);
  },
  post: function requestPost(url, options) {
    return requestWrap('POST', url, options);
{'fraction_non_alphanumeric': 0.13689395903551985, 'fraction_numerical': 0.0070002592688618095, 'mean_word_length': 2.9447852760736195, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1047217', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1135, 'n_words': 263}