Bug 1757145 - Make sure content-length is consistent with the actrual data bytes, r=necko-reviewers,valentin

Differential Revision: https://phabricator.services.mozilla.com/D139929
This commit is contained in:
Kershaw Chang 2022-03-03 13:36:15 +00:00
Родитель df78ebf179
Коммит 9d6e072a2c
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -417,7 +417,7 @@ function handleRequest(req, res) {
// DNS response header is 12 bytes, we check for this minimum length
// at the start of decoding so this is the simplest way to force
// a decode error.
return "\x0F\x0F\x0F\x0F";
return "\xFF\xFF\xFF\xFF";
}
function responseData() {
@ -521,10 +521,11 @@ function handleRequest(req, res) {
}
});
} else {
resp.setHeader("Content-Length", buffer.length);
const output = Buffer.from(buffer, "utf-8");
resp.setHeader("Content-Length", output.length);
try {
resp.writeHead(200);
resp.write(buffer);
resp.write(output);
resp.end("");
} catch (e) {
// connection was closed by the time we started writing.