Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async onRequestWillBeSent(params: Crdp.Network.RequestWillBeSentEvent) {
const requestUrl: string = params.request.url;
debug(`About to start fetching ${cutString(requestUrl)} (${params.requestId})`);
this._requests.set(params.requestId, params);
if (!this._headers) {
// TODO: do some clean up, we probably don't want all the headers as the "defaults".
this._headers = params.request.headers;
}
if (params.redirectResponse) {
debug(`Redirect found for ${cutString(requestUrl)}`);
if (requestUrl === params.redirectResponse.url) {
logger.error(`Error redirecting: ${requestUrl} is an infinite loop`);
return;
}
const hops = this._redirects.calculate(requestUrl);
// We limit the number of redirects
if (hops.length >= 10) {
logger.error(`More than 10 redirects found for ${requestUrl}`);
return;
}
self._rawResponse = value;
}
return value;
});
}
};
debug(`Content for ${cutString(cdpResponse.response.url)} downloaded`);
return returnValue;
} catch (e) {
debug(`Body requested after connection closed for request ${cdpResponse.requestId}`);
defaultBody.rawContent = Buffer.alloc(0);
debug(`Content for ${cutString(cdpResponse.response.url)} downloaded`);
return defaultBody;
}
}
.then((result) => {
const { response: { body: { rawResponse: rr } } } = result;
return rr();
})
.then((value) => {
if (self) {
self._rawResponse = value;
}
return value;
});
}
};
debug(`Content for ${cutString(cdpResponse.response.url)} downloaded`);
return returnValue;
} catch (e) {
debug(`Body requested after connection closed for request ${cdpResponse.requestId}`);
defaultBody.rawContent = Buffer.alloc(0);
debug(`Content for ${cutString(cdpResponse.response.url)} downloaded`);
return defaultBody;
}
}