Skip to content

Commit

Permalink
Add debug info for request body
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Nov 1, 2019
1 parent 3c8651b commit 7a3b0dc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/index.js
Expand Up @@ -124,9 +124,21 @@ exports.request = function (url, opts) {

// string
if (!body || 'string' === typeof body || body instanceof Buffer) {
if (debugBody.enabled) {
if (!body) {
debugBody('<no request body>');
} else if ('string' === typeof body) {
debugBody(body);
} else {
debugBody(`Buffer <ignored>, Buffer length: ${body.length}`);
}
}
request.end(body);
} else if ('function' === typeof body.pipe) { // stream
body.pipe(request);
if (debugBody.enabled) {
debugBody('<request body is a stream>');
}
body.once('error', (err) => {
abort(append(err, 'HttpX', 'Stream occor error'));
});
Expand Down Expand Up @@ -223,7 +235,7 @@ exports.read = function (response, encoding) {
return resolve(result);
}

debugBody('Buffer <ignored>');
debugBody(`Buffer <ignored>, Buffer length: ${buff.length}`);
resolve(buff);
};

Expand Down

0 comments on commit 7a3b0dc

Please sign in to comment.