Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
// @ts-check
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// imports
//
const os = require('os');
// const http = require('http');
// const https = require('https');
const crypto = require('crypto');
const fs = require('fs');
const http = require('follow-redirects').http;
const https = require('follow-redirects').https;
require('follow-redirects').maxRedirects = 15; // 3X the default!!! we want to know when there *really* is many
const url = require('url');
const request = require('request');
const fetch = require('node-fetch');
// https://github.com/wdavidw/node-http-status/blob/master/lib/index.js
const http_status = require('http-status');
const valid_url = require('valid-url');
// https://www.npmjs.com/package/wget-improved
const wget = require('wget-improved');
const robots_parser = require('robots-parser');
const util = require('util');
const inspect_obj = (obj) => {return util.inspect(obj, { showHidden: true, depth: null });};
const cheerio = require('cheerio');
const S = require('string');
const hasBom = require('has-bom');
// const {URL} = require('url');
const URL = require('url-parse');
const proxy = (req, body, host, maxRedirects, callback) => {
followRedirects.maxRedirects = maxRedirects
const uri = new url.URL(host)
const protocol = uri.protocol.replace(':', '')
// if maxRedirects is enabled in settings the client still can disable
// redirect for custom request by setting the maxredirects header to 0
let redirect = maxRedirects > 0
if (req.headers.maxredirects === '0') {
redirect = false
}
const mod = redirect
? followRedirects[protocol] || followRedirects.http
: modMapping[protocol] || http
const pReq = mod.request(
{