lib/connect-injector.js
function (data, encoding) {
        var self = this;
        var _super = this._super.bind(this);

        if (!this._interceptCheck()) {
          debug('not intercepting, ending with original .end');
          return _super(data, encoding);
        }

        if (data) {
          this.write(data, encoding);
        }

        debug('resetting to original response.write');
        this.write = oldWrite;

        // Responses without a body can just be ended
        if(!this._hasBody || !this._interceptBuffer) {
          debug('ending empty resopnse without injecting anything');
          return _super();
        }

        var gzipped = this.getHeader('content-encoding') === 'gzip';
        var chain = Q(this._interceptBuffer.getContents());

        if(gzipped) {
          debug('unzipping content');
          // Unzip the buffer
          chain = chain.then(function(buffer) {
            return Q.nfcall(zlib.gunzip, buffer);
          });
        }

        this.injectors.forEach(function(injector) {
          // Run all converters, if they are active
          // In series, using the previous output
          if(injector.active) {
            debug('adding injector to chain');
            var converter = injector.converter.bind(self);
            chain = chain.then(function(prev) {
              return Q.nfcall(converter, prev, req, res);
            });
          }
        });

        if(gzipped) {
          debug('re-zipping content');
          // Zip it again
          chain = chain.then(function(result) {
            return Q.nfcall(zlib.gzip, result);
          });
        }

        chain.then(_super).fail(function(e) {
          debug('injector chain failed, emitting error event');
          self.emit('error', e);
        });

        return true;
      }
function (data, encoding) {
        var self = this;
        var _super = this._super.bind(this);

        if (!this._interceptCheck()) {
          debug('not intercepting, ending with original .end');
          return _super(data, encoding);
        }

        if (data) {
          this.write(data, encoding);
        }

        debug('resetting to original response.write');
        this.write = oldWrite;

        // Responses without a body can just be ended
        if(!this._hasBody || !this._interceptBuffer) {
          debug('ending empty resopnse without injecting anything');
          return _super();
        }

        var gzipped = this.getHeader('content-encoding') === 'gzip';
        var chain = Q(this._interceptBuffer.getContents());

        if(gzipped) {
          debug('unzipping content');
          // Unzip the buffer
          chain = chain.then(function(buffer) {
            return Q.nfcall(zlib.gunzip, buffer);
          });
        }

        this.injectors.forEach(function(injector) {
          // Run all converters, if they are active
          // In series, using the previous output
          if(injector.active) {
            debug('adding injector to chain');
            var converter = injector.converter.bind(self);
            chain = chain.then(function(prev) {
              return Q.nfcall(converter, prev, req, res);
            });
          }
        });

        if(gzipped) {
          debug('re-zipping content');
          // Zip it again
          chain = chain.then(function(result) {
            return Q.nfcall(zlib.gzip, result);
          });
        }

        chain.then(_super).fail(function(e) {
          debug('injector chain failed, emitting error event');
          self.emit('error', e);
        });

        return true;
      }
function ( data , encoding ) { var self = this ; var _super = this . _super . bind ( this ) ; if ( ! this . _interceptCheck ( ) ) { debug ( 'not intercepting, ending with original .end' ) ; return _super ( data , encoding ) ; } if ( data ) { this . write ( data , encoding ) ; } debug ( 'resetting to original response.write' ) ; this . write = oldWrite ; // Responses without a body can just be ended if ( ! this . _hasBody || ! this . _interceptBuffer ) { debug ( 'ending empty resopnse without injecting anything' ) ; return _super ( ) ; } var gzipped = this . getHeader ( 'content-encoding' ) === 'gzip' ; var chain = Q ( this . _interceptBuffer . getContents ( ) ) ; if ( gzipped ) { debug ( 'unzipping content' ) ; // Unzip the buffer chain = chain . then ( function ( buffer ) { return Q . nfcall ( zlib . gunzip , buffer ) ; } ) ; } this . injectors . forEach ( function ( injector ) { // Run all converters, if they are active // In series, using the previous output if ( injector . active ) { debug ( 'adding injector to chain' ) ; var converter = injector . converter . bind ( self ) ; chain = chain . then ( function ( prev ) { return Q . nfcall ( converter , prev , req , res ) ; } ) ; } } ) ; if ( gzipped ) { debug ( 're-zipping content' ) ; // Zip it again chain = chain . then ( function ( result ) { return Q . nfcall ( zlib . gzip , result ) ; } ) ; } chain . then ( _super ) . fail ( function ( e ) { debug ( 'injector chain failed, emitting error event' ) ; self . emit ( 'error' , e ) ; } ) ; return true ; }
End the request.
End the request .