deep-framework
Version:
30 lines (25 loc) • 867 B
JavaScript
var _ = require('underscore');
/**
* Represents an outgoing HTTP/HTTPS call.
* @constructor
* @param {http.ClientRequest|https.ClientRequest} req - The request object from the HTTP/HTTPS call.
* @param {http.IncomingMessage|https.IncomingMessage} res - The response object from the HTTP/HTTPS call.
* @param {boolean} traced - The boolean for if the segment was traced.
*/
function Remote(req, res, traced) {
this.init(req, res, traced);
}
Remote.prototype.init = function init(req, res, traced) {
this.request = {
url: (req.agent.protocol + '//' + req.getHeader('host') + req.path) || '',
method: req.method || '',
traced: traced
};
if (res) {
this.response = {
status: res.statusCode || '',
content_length: _.has(res.headers, 'content-length') ? res.headers['content-length'] : 0
};
}
};
module.exports = Remote;