gecko-dev/toolkit/components/remotebrowserutils/tests/browser/print_postdata.sjs
Nika Layzell d756214c1f Bug 1467223 - Part 6: Add basic test for process-changing POST loads, r=qdot
This test checks that POST data can be submitted from both file and
moz-extension URIs to web content without the data being lost, or the
load being performed in the incorrect process.

Depends on D15612

Differential Revision: https://phabricator.services.mozilla.com/D15613

--HG--
extra : moz-landing-system : lando
2019-01-23 21:07:13 +00:00

22 lines
719 B
JavaScript

const CC = Components.Constructor;
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream");
function handleRequest(request, response) {
response.setHeader("Content-Type", "text/plain", false);
if (request.method == "GET") {
response.write(request.queryString);
} else {
var body = new BinaryInputStream(request.bodyInputStream);
var avail;
var bytes = [];
while ((avail = body.available()) > 0)
Array.prototype.push.apply(bytes, body.readByteArray(avail));
var data = String.fromCharCode.apply(null, bytes);
response.bodyOutputStream.write(data, data.length);
}
}