On my system, I get several requests, I would like to know if there is a way to get the size of this request ( req
) received in kbs
, to get a sense of how much bandwidth was spent for this send .
On my system, I get several requests, I would like to know if there is a way to get the size of this request ( req
) received in kbs
, to get a sense of how much bandwidth was spent for this send .
You can use the request-stats module
var requestStats = require('request-stats');
var stats = requestStats(server);
stats.on('complete', function (detalhes) {
var tamanho = detalhes.req.bytes;
});
Note that the variable tamanho
will receive the amount of bytes from the request, if you want to display it in Kbytes you only need to divide by 1024. >
The object detalhes
will look something like this
{
ok: true, //Se a conexão foi fechada corretamente
time: 0, // O tempo (em ms) que foi levado para servir a requisição
req: {
bytes: 0, // Quantidade de bytes da requisição
headers: { ... }, // O headers HTTP da requisição
method: 'POST', // O método HTTP usado pelo client
path: '...' // O caminho da URL requisitada
},
res : {
bytes: 0, // Quantidade de bytes da resposta
headers: { ... }, // Os headers da resposta
status: 200 // O código HTTP da resposta
}
}
There is also header HTTP called Content-Length , however, some clients may not send this header or send it with a value not true.
If you want to use it, you can get the value of it by the property headers
by searching for the key content-length
.
var tamanho = req.headers['content-length'];