code: function hammockRequest(handler, opts, cb) {
      var mockReq = HammockRequest(opts);
      var mockRes = HammockResponse(onResponse);
  
      if (opts.url.indexOf('http:') !== 0 &&
          opts.url.indexOf('https:') !== 0
      ) {
          opts.url = 'http://localhost' + opts.url;
      }
  
      var uri = url.parse(opts.url);
  
      if ('json' in opts && opts.json !== true) {
          mockReq.headers['content-type'] = 'application/json';
      }
  
      if (opts.jar) {
          var cookies = opts.jar.getCookieStringSync(uri.href);
          if (cookies && cookies.length) {
              if (Array.isArray(cookies)) {
                  cookies = cookies.join('; ');
              }
              mockReq.headers = mockReq.headers || {};
              mockReq.headers.cookie = cookies;
          }
      }
  
      if (typeof handler === 'function') {
          handler(mockReq, mockRes);
      } else if (handler && typeof handler.emit === 'function') {
          handler.emit('request', mockReq, mockRes);
      } else {
          throw new Error('invalid handler function');
      }
  
      if ('json' in opts && opts.json !== true) {
          mockReq.write(JSON.stringify(opts.json));
          mockReq.end();
      } else {
          mockReq.end();
      }
  
      function onResponse(err, resp) {
          if (err) {
              return cb(err);
          }
  
          if (typeof resp.statusCode !== 'number') {
              resp.statusCode = 200;
          }
  
          if ('json' in opts) {
              resp.body = JSON.parse(resp.body);
          }
  
          if (opts.jar && resp.headers['set-cookie']) {
              var header = resp.headers['set-cookie'];
              if (Array.isArray(header)) {
                  header = header.join('; ');
              }
              var cookie = tough.Cookie.parse(header);
              opts.jar.setCookieSync(cookie, uri.href);
          }
  
          cb(null, resp);
      }
  }
docs: /*eslint max-statements: [2, 25]