src/cache.js
function playback(resHeaders, resBody) {
        if (!forceLive) {
          var headerContent = fs.readFileSync(filename + '.headers');
          resHeaders = JSON.parse(headerContent);
        }

        var socket = new EventEmitter();
        socket.setTimeout = socket.setEncoding = function() {};
        // Needed for node 0.8.x
        socket.destroy = socket.pause = socket.resume = function() {};

        req.socket = socket;
        req.emit('socket', socket);

        if (resHeaders.timeout) {
          socket.emit('timeout');
          req.emit('error', new Error('Timeout'));
          return;
        }

        if (resHeaders.error) {
          req.emit('error', resHeaders.error);
          return;
        }

        var res = new http.IncomingMessage(socket);
        res.headers = resHeaders.headers || {};
        res.statusCode = resHeaders.statusCode;

        if (callback) {
          callback(res);
        }

        if (!forceLive) {
          resBody = fs.readFileSync(filename);
        }

        req.emit('response', res);

        if (res.push) {
          // node 0.10.x
          res.push(resBody);
          res.push(null);
        } else {
          // node 0.8.x
          res.emit('data', resBody);
          res.emit('end');
        }
      }
function playback(resHeaders, resBody) {
        if (!forceLive) {
          var headerContent = fs.readFileSync(filename + '.headers');
          resHeaders = JSON.parse(headerContent);
        }

        var socket = new EventEmitter();
        socket.setTimeout = socket.setEncoding = function() {};
        // Needed for node 0.8.x
        socket.destroy = socket.pause = socket.resume = function() {};

        req.socket = socket;
        req.emit('socket', socket);

        if (resHeaders.timeout) {
          socket.emit('timeout');
          req.emit('error', new Error('Timeout'));
          return;
        }

        if (resHeaders.error) {
          req.emit('error', resHeaders.error);
          return;
        }

        var res = new http.IncomingMessage(socket);
        res.headers = resHeaders.headers || {};
        res.statusCode = resHeaders.statusCode;

        if (callback) {
          callback(res);
        }

        if (!forceLive) {
          resBody = fs.readFileSync(filename);
        }

        req.emit('response', res);

        if (res.push) {
          // node 0.10.x
          res.push(resBody);
          res.push(null);
        } else {
          // node 0.8.x
          res.emit('data', resBody);
          res.emit('end');
        }
      }
function playback ( resHeaders , resBody ) { if ( ! forceLive ) { var headerContent = fs . readFileSync ( filename + '.headers' ) ; resHeaders = JSON . parse ( headerContent ) ; } var socket = new EventEmitter ( ) ; socket . setTimeout = socket . setEncoding = function ( ) { } ; // Needed for node 0.8.x socket . destroy = socket . pause = socket . resume = function ( ) { } ; req . socket = socket ; req . emit ( 'socket' , socket ) ; if ( resHeaders . timeout ) { socket . emit ( 'timeout' ) ; req . emit ( 'error' , new Error ( 'Timeout' ) ) ; return ; } if ( resHeaders . error ) { req . emit ( 'error' , resHeaders . error ) ; return ; } var res = new http . IncomingMessage ( socket ) ; res . headers = resHeaders . headers || { } ; res . statusCode = resHeaders . statusCode ; if ( callback ) { callback ( res ) ; } if ( ! forceLive ) { resBody = fs . readFileSync ( filename ) ; } req . emit ( 'response' , res ) ; if ( res . push ) { // node 0.10.x res . push ( resBody ) ; res . push ( null ) ; } else { // node 0.8.x res . emit ( 'data' , resBody ) ; res . emit ( 'end' ) ; } }
Only called if either the fixture with the constructed filename exists, or we're playing back passed in data.
Only called if either the fixture with the constructed filename exists or we re playing back passed in data .