nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 320 forks source link

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

Open dbit-xia opened 1 month ago

dbit-xia commented 1 month ago

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);
    }