lib/collection/response.js
function () {
        var sizeInfo = {
                body: 0,
                header: 0,
                total: 0
            },

            contentEncoding = this.headers.get(CONTENT_ENCODING),
            contentLength = this.headers.get(CONTENT_LENGTH),
            isCompressed = false,
            byteLength;

        // if server sent encoded data, we should first try deriving length from headers
        if (_.isString(contentEncoding)) {
            // desensitise case of content encoding
            contentEncoding = contentEncoding.toLowerCase();
            // eslint-disable-next-line lodash/prefer-includes
            isCompressed = (contentEncoding.indexOf('gzip') > -1) || (contentEncoding.indexOf('deflate') > -1);
        }

        // if 'Content-Length' header is present and encoding is of type gzip/deflate, we take body as declared by
        // server. else we need to compute the same.
        if (contentLength && isCompressed && util.isNumeric(contentLength)) {
            sizeInfo.body = _.parseInt(contentLength, 10);
        }
        // if there is a stream defined which looks like buffer, use it's data and move on
        else if (this.stream) {
            byteLength = this.stream.byteLength;
            sizeInfo.body = util.isNumeric(byteLength) ? byteLength : 0;
        }
        // otherwise, if body is defined, we try get the true length of the body
        else if (!_.isNil(this.body)) {
            sizeInfo.body = supportsBuffer ? Buffer.byteLength(this.body.toString()) : this.body.toString().length;
        }

        // size of header is added
        // https://tools.ietf.org/html/rfc7230#section-3
        // HTTP-message   = start-line (request-line / status-line)
        //                  *( header-field CRLF )
        //                  CRLF
        //                  [ message-body ]
        // status-line = HTTP-version SP status-code SP reason-phrase CRLF
        sizeInfo.header = (HTTP_X_X + SP + this.code + SP + this.reason() + CRLF + CRLF).length +
            this.headers.contentSize();

        // compute the approximate total body size by adding size of header and body
        sizeInfo.total = (sizeInfo.body || 0) + (sizeInfo.header || 0);
        return sizeInfo;
    }
function () {
        var sizeInfo = {
                body: 0,
                header: 0,
                total: 0
            },

            contentEncoding = this.headers.get(CONTENT_ENCODING),
            contentLength = this.headers.get(CONTENT_LENGTH),
            isCompressed = false,
            byteLength;

        // if server sent encoded data, we should first try deriving length from headers
        if (_.isString(contentEncoding)) {
            // desensitise case of content encoding
            contentEncoding = contentEncoding.toLowerCase();
            // eslint-disable-next-line lodash/prefer-includes
            isCompressed = (contentEncoding.indexOf('gzip') > -1) || (contentEncoding.indexOf('deflate') > -1);
        }

        // if 'Content-Length' header is present and encoding is of type gzip/deflate, we take body as declared by
        // server. else we need to compute the same.
        if (contentLength && isCompressed && util.isNumeric(contentLength)) {
            sizeInfo.body = _.parseInt(contentLength, 10);
        }
        // if there is a stream defined which looks like buffer, use it's data and move on
        else if (this.stream) {
            byteLength = this.stream.byteLength;
            sizeInfo.body = util.isNumeric(byteLength) ? byteLength : 0;
        }
        // otherwise, if body is defined, we try get the true length of the body
        else if (!_.isNil(this.body)) {
            sizeInfo.body = supportsBuffer ? Buffer.byteLength(this.body.toString()) : this.body.toString().length;
        }

        // size of header is added
        // https://tools.ietf.org/html/rfc7230#section-3
        // HTTP-message   = start-line (request-line / status-line)
        //                  *( header-field CRLF )
        //                  CRLF
        //                  [ message-body ]
        // status-line = HTTP-version SP status-code SP reason-phrase CRLF
        sizeInfo.header = (HTTP_X_X + SP + this.code + SP + this.reason() + CRLF + CRLF).length +
            this.headers.contentSize();

        // compute the approximate total body size by adding size of header and body
        sizeInfo.total = (sizeInfo.body || 0) + (sizeInfo.header || 0);
        return sizeInfo;
    }
function ( ) { var sizeInfo = { body : 0 , header : 0 , total : 0 } , contentEncoding = this . headers . get ( CONTENT_ENCODING ) , contentLength = this . headers . get ( CONTENT_LENGTH ) , isCompressed = false , byteLength ; // if server sent encoded data, we should first try deriving length from headers if ( _ . isString ( contentEncoding ) ) { // desensitise case of content encoding contentEncoding = contentEncoding . toLowerCase ( ) ; // eslint-disable-next-line lodash/prefer-includes isCompressed = ( contentEncoding . indexOf ( 'gzip' ) > - 1 ) || ( contentEncoding . indexOf ( 'deflate' ) > - 1 ) ; } // if 'Content-Length' header is present and encoding is of type gzip/deflate, we take body as declared by // server. else we need to compute the same. if ( contentLength && isCompressed && util . isNumeric ( contentLength ) ) { sizeInfo . body = _ . parseInt ( contentLength , 10 ) ; } // if there is a stream defined which looks like buffer, use it's data and move on else if ( this . stream ) { byteLength = this . stream . byteLength ; sizeInfo . body = util . isNumeric ( byteLength ) ? byteLength : 0 ; } // otherwise, if body is defined, we try get the true length of the body else if ( ! _ . isNil ( this . body ) ) { sizeInfo . body = supportsBuffer ? Buffer . byteLength ( this . body . toString ( ) ) : this . body . toString ( ) . length ; } // size of header is added // https://tools.ietf.org/html/rfc7230#section-3 // HTTP-message   = start-line (request-line / status-line) //                  *( header-field CRLF ) //                  CRLF //                  [ message-body ] // status-line = HTTP-version SP status-code SP reason-phrase CRLF sizeInfo . header = ( HTTP_X_X + SP + this . code + SP + this . reason ( ) + CRLF + CRLF ) . length + this . headers . contentSize ( ) ; // compute the approximate total body size by adding size of header and body sizeInfo . total = ( sizeInfo . body || 0 ) + ( sizeInfo . header || 0 ) ; return sizeInfo ; }
Get the response size by computing the same from content length header or using the actual response body.

@returns {Number}
@todo write unit tests
Get the response size by computing the same from content length header or using the actual response body .