Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
retryRequest(uri, { request: this.request }, (error, response) => {
if (error || response.statusCode !== 200) {
return reject(error || uri);
}
const req: Object = {};
const res: Object = response;
// Set circular references:
res.req = req;
req.res = res;
// Alter the prototypes:
setPrototypeOf(req, this.req);
setPrototypeOf(res, this.res);
resolve({ req, res, uri });
request( uri, resolve, reject ) {
if ( !uri.startsWith( this.base ) )
uri = url.resolve( this.base, uri );
request( uri, ( error, response ) => {
if ( error || response.statusCode != 200 ) {
reject( error || uri );
}
const req = {};
const res = response;
// Set circular references:
res.req = req;
req.res = res;
// Alter the prototypes:
req.__proto__ = this.req;
res.__proto__ = this.res;
resolve( req, res );