unit
unit copied to clipboard
nodejs: Need to be compatible with non-utf8 text responses
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);
}