unit icon indicating copy to clipboard operation
unit copied to clipboard

nodejs: Need to be compatible with non-utf8 text responses

Open dbit-xia opened this issue 9 months ago • 0 comments

Version number: unit 1.32.1

When sending non-single byte text and specifying a non-UTF8 encoding, it will cause the server to hang, and all requests will stop responding!

return res.end("夏天", 'latin1');

I tried using the following code and it works fine, (Consistent results with nodejs native)

//ServerResponse.prototype._writeBody

    if (type chunk === 'string'
        && encoding && (['utf8', 'utf-8'].includes(encoding.toLowerCase()) === false)) {
        chunk = Buffer.from(chunk, encoding);
    }

dbit-xia avatar May 24 '24 09:05 dbit-xia