fune/docshell/test/navigation/file_reload_large_postdata.sjs
Nika Layzell 91f9c9c927 Bug 1681529 - Part 1: Add a test for reloading a page with a large postdata payload, r=peterv
Without the other patches in this series, this test fails with both with and
without Fission enabled, for two different reasons.

With Fission disabled, the second reload request appears as empty, due to us
being unable to rewind the postData nsIInputStream. With Fission enabled, the
second reload request causes crashes due to the nsMIMEInputStream's invariant of
requiring a seekable stream is invalidated, causing the nsICloneableInputStream
implementation to misbehave.

Differential Revision: https://phabricator.services.mozilla.com/D101800
2021-02-04 18:12:52 +00:00

46 lines
1.1 KiB
JavaScript

/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80 ft=javascript: */
"use strict";
const BinaryInputStream = Components.Constructor(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream"
);
Cu.importGlobalProperties(["URLSearchParams"]);
function readStream(inputStream) {
let available = 0;
let result = [];
while ((available = inputStream.available()) > 0) {
result.push(inputStream.readBytes(available));
}
return result.join("");
}
function handleRequest(request, response) {
let rv = (() => {
try {
if (request.method != "POST") {
return "ERROR: not a POST request";
}
let body = new URLSearchParams(
readStream(new BinaryInputStream(request.bodyInputStream))
);
return body.get("payload").length;
} catch (e) {
return "ERROR: Exception: " + e;
}
})();
response.setHeader("Content-Type", "text/html", false);
response.setHeader("Cache-Control", "no-cache", false);
response.write(`<!DOCTYPE HTML>
<script>
let rv = (${JSON.stringify(rv)});
opener.postMessage(rv, "*");
</script>
`);
}