Skip to content

Commit

Permalink
Merge pull request #4522 from Nriver/master
Browse files Browse the repository at this point in the history
fix decoding issue for request data chunks
  • Loading branch information
zadam authored Dec 27, 2023
2 parents 33af9a3 + 30c3c10 commit a378313
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/services/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ function exec(opts) {
}

let responseStr = '';
let chunks = [];

response.on('data', chunk => responseStr += chunk);
response.on('data', chunk => chunks.push(chunk));

response.on('end', () => {
// use Buffer instead of string concatenation to avoid implicit decoding for each chunk
// decode the entire data chunks explicitly as utf-8
responseStr = Buffer.concat(chunks).toString('utf-8')

if ([200, 201, 204].includes(response.statusCode)) {
try {
const jsonObj = responseStr.trim() ? JSON.parse(responseStr) : null;
Expand Down

0 comments on commit a378313

Please sign in to comment.