Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
interceptor.intercept(/.*/, m).reply(function(_, body, respond) {
const { req, method } = this;
const { headers } = req;
const parsedArguments = normalizeClientRequestArgs(
...REQUEST_ARGUMENTS.get(req)
);
const url = getUrlFromOptions(parsedArguments.options);
if (body) {
if (
typeof body === 'string' &&
!isUtf8Representable(Buffer.from(body, 'hex'))
) {
// Nock internally converts a binary buffer into its hexadecimal
// representation so convert it back to a buffer.
body = Buffer.from(body, 'hex');
} else if (isJSONContent(headers)) {
// Nock will parse json content into an object. We have our own way
// of dealing with json content so convert it back to a string.
body = JSON.stringify(body);
function parseArgs() {
const args = normalizeClientRequestArgs(...arguments);
if (moduleName === 'https') {
args.options = {
...{ port: 443, protocol: 'https:', _defaultAgent: globalAgent },
...args.options
};
} else {
args.options = {
...{ port: 80, protocol: 'http:' },
...args.options
};
}
return args;
}