Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
enqueue(url, customData, auth={})
{
let link;
// Undocumented internal use: `enqueue(Link)`
if (url instanceof Link)
{
link = url;
}
// Documented use: `enqueue(URL)`
else if (isURL.lenient(url))
{
link = new Link().resolve(url);
}
else
{
throw new TypeError("Invalid URL");
}
const id = this.#linkQueue.enqueue(link.get(REBASED_URL), { auth, customData, link });
this.emit(QUEUE_EVENT);
return id;
}
if (!is.string(url) && !is.object(url)) {
throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
} else if (is.string(url)) {
url = url.replace(/^unix:/, 'http://$&');
try {
decodeURI(url);
} catch (err) {
throw new Error('Parameter `url` must contain valid UTF-8 character sequences');
}
url = urlParseLax(url);
if (url.auth) {
throw new Error('Basic authentication must be done with the `auth` option');
}
} else if (isURL.lenient(url)) {
url = urlToOptions(url);
}
opts = Object.assign(
{
path: '',
retries: 2,
cache: false,
decompress: true,
useElectronNet: false,
throwHttpErrors: true
},
url,
{
protocol: url.protocol || 'http:' // Override both null/undefined with default protocol
},
export default async (url, auth, cache, options) =>
{
if (!isURL.lenient(url))
{
throw new TypeError(BLC_INVALID);
}
else
{
url = new URL(url);
url.hash = "";
url.pathname = "/robots.txt";
url.search = "";
const {stream} = await requestHTTP(url, auth, GET_METHOD, cache, options);
// @todo https://github.com/tc39/proposal-pipeline-operator
return guard(await parse(stream));
}
};
if (!is.string(url) && !is.object(url)) {
throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
} else if (is.string(url)) {
url = url.replace(/^unix:/, 'http://$&');
try {
decodeURI(url);
} catch (err) {
throw new Error('Parameter `url` must contain valid UTF-8 character sequences');
}
url = urlParseLax(url);
if (url.auth) {
throw new Error('Basic authentication must be done with the `auth` option');
}
} else if (isURL.lenient(url)) {
url = urlToOptions(url);
}
opts = Object.assign(
{
path: '',
retries: 2,
cache: false,
decompress: true,
useElectronNet: false,
throwHttpErrors: true
},
url,
{
protocol: url.protocol || 'http:' // Override both null/undefined with default protocol
},
module.exports = (proxy, opts) => {
proxy = proxy || getProxy();
opts = Object.assign({}, opts);
if (typeof proxy === 'object') {
opts = proxy;
proxy = getProxy();
}
if (!proxy) {
return null;
}
proxy = isurl.lenient(proxy) ? urlToOptions(proxy) : url.parse(proxy);
const uriProtocol = opts.protocol === 'https' ? 'https' : 'http';
const proxyProtocol = proxy.protocol === 'https:' ? 'Https' : 'Http';
const port = proxy.port || (proxyProtocol === 'Https' ? 443 : 80);
const method = `${uriProtocol}Over${proxyProtocol}`;
delete opts.protocol;
return tunnelAgent[method](Object.assign({
proxy: {
port,
host: proxy.hostname,
proxyAuth: proxy.auth
}
}, opts));
};
enqueue(url, data, options)
{
if (!isURL.lenient(url))
{
throw new TypeError("Invalid URL");
}
else
{
const hostKey = normalizeURL(url, this.#options, options);
const id = this.#idCounter++;
this.#items[id] = { active:false, data, hostKey, id, options, url };
this.#priorityQueue.push(id);
this.#maybeStartNext();
return id;
}
}