Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public fetchContent(target: URL | string, customHeaders?: object): Promise {
/*
* TODO: This should create a new tab, navigate to the
* resource and control what is received somehow via an event.
*/
const assigns = compact([this && this._headers, customHeaders]);
const headers = Object.assign({}, ...assigns);
const href = typeof target === 'string' ? target : target.href;
const options = {
headers,
// we sync the ignore SSL error options with `request`. This is neeeded for local https tests
rejectUnauthorized: !this._options.ignoreHTTPSErrors,
strictSSL: !this._options.ignoreHTTPSErrors
};
const request = new Requester(options);
return request.get(href);
}
private fetchContent(href: string, headers: HttpHeaders) {
const options = {
headers,
// we sync the ignore SSL error options with `request`. This is neeeded for local https tests
rejectUnauthorized: !this._ignoreHTTPSErrors,
strictSSL: !this._ignoreHTTPSErrors
};
const request: Requester = new Requester(options);
return request.get(href);
}
private _fetchUrl(target: URL, customHeaders?: object): Promise {
const uri: string = url.format(target);
/* istanbul ignore else */
if (!customHeaders) {
return this.request.get(uri);
}
const r: Requester = new Requester({
headers: customHeaders,
rejectUnauthorized: !this._options.ignoreHTTPSErrors,
strictSSL: !this._options.ignoreHTTPSErrors
});
return r.get(uri);
}
public constructor(server: Engine, config?: any) {
this._options = { ...defaultOptions, ...config };
const requesterOptions = {
rejectUnauthorized: !this._options.ignoreHTTPSErrors,
strictSSL: !this._options.ignoreHTTPSErrors,
...this._options.requestOptions || {}
};
this.request = new Requester(requesterOptions);
this.server = server;
this._timeout = server.timeout;
this._subprocesses = new Set();
(server as Engine).on('parse::end::html', (event) => {
/* istanbul ignore if */
if (!this._originalDocument) {
this._originalDocument = event.document;
}
});
}
public fetchContent(target: URL | string, customHeaders?: object): Promise {
/*
* TODO: This should create a new tab, navigate to the
* resource and control what is received somehow via an event.
*/
const href: string = typeof target === 'string' ? target : target.href;
const options = {
headers: customHeaders || {},
// we sync the ignore SSL error options with `request`. This is neeeded for local https tests
rejectUnauthorized: !this._options.ignoreHTTPSErrors,
strictSSL: !this._options.ignoreHTTPSErrors
};
const request: Requester = new Requester(options);
return request.get(href);
}
public constructor(context: HintContext) {
const options: CoreOptions = { method: context.hintOptions && context.hintOptions.method ? context.hintOptions.method : 'GET' };
const requester = new Requester(options);
const brokenStatusCodes = [404, 410, 500, 503];
/** Stores the elements with their URLs which have been collected while traversing the page. */
const collectedElementsWithURLs: [HTMLElement, string[]][] = [];
/** Stores the URLs and it's response status codes */
const fetchedURLs: any[] = [];
/** Returns an array with all the URLs in the given `srcset` attribute or an empty string if none. */
const parseSrcSet = (element: HTMLElement): string[] => {
const srcset = element.getAttribute('srcset');
if (!srcset) {
return [];
}