All files / lib/middleware info.js

8% Statements 2/25
0% Branches 0/4
0% Functions 0/4
8.7% Lines 2/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50              1x   1x                                                                                
"use strict";
/**
 * Contains proxy middlewares
 *
 * @module
 */
 
var _ = require("lodash");
 
module.exports = function () {
    if (!this.responsesData) return false;
 
    var res = this.res;
    var req = this.req;
 
    var data = { name: req.headers.host + req.url,
        method: req.method,
        reqHeaders: req.headers,
        resHeaders: {},
        statusCode: null,
        statusMessage: null,
        size: 0,
        chunkSizes: [] };
    this.responsesData.push(data);
 
    var resWrite = res.write;
    var resEnd = res.end;
 
    var addData = chunk => {
        if (!chunk) return;
        data.chunkSizes.push(chunk.length);
        data.size += chunk.length;
    };
 
    res.write = function (chunk) {
        addData(chunk);
        resWrite.apply(this, arguments);
    };
 
    res.end = function (chunk) {
        addData(chunk);
        data.resHeaders = _.cloneDeep(res.headers);
        data.statusCode = res.statusCode;
        data.statusMessage = res.statusMessage;
        resEnd.apply(this, arguments);
    };
 
    return false;
};