Fix faulty content-length comparison in utils/http-helpers.js.

Since body is a string, body.length is not necessarily the number of bytes
in the response body.
This commit is contained in:
Ben Newman
2017-04-20 16:09:51 -04:00
committed by Jesse Rosenberger
parent 3438a3ac94
commit 1a036553c1

View File

@@ -310,12 +310,16 @@ _.extend(exports, {
var req = request(options, function (error, response, body) {
if (! error && response && body) {
const contentLength = Number(response.headers["content-length"]);
if (contentLength > 0 && body.length < contentLength) {
const actualLength = Buffer.byteLength(body);
if (contentLength > 0 &&
actualLength < contentLength) {
error = new Error(
"Expected " + contentLength + " bytes in request body " +
"but received only " + body.length);
"but received only " + actualLength);
}
}
return callback.call(this, error, response, body);
});