How to use the nock/lib/common.normalizeClientRequestArgs function in nock

To help you get started, we’ve selected a few nock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Netflix / pollyjs / packages / @pollyjs / adapter-node-http / src / index.js View on Github external
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);
github Netflix / pollyjs / packages / @pollyjs / adapter-node-http / src / index.js View on Github external
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;
      }