blob: 1a1fa5d89cdd39770792a1ed515e2ac60ee8bee2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
"use strict";
const CC = Components.Constructor;
const BinaryInputStream = CC(
"@mozilla.org/binaryinputstream;1",
"nsIBinaryInputStream",
"setInputStream"
);
const BinaryOutputStream = CC(
"@mozilla.org/binaryoutputstream;1",
"nsIBinaryOutputStream",
"setOutputStream"
);
function log(str) {
// dump(`LOG: ${str}\n`);
}
async function handleRequest(request, response) {
if (request.method !== "POST") {
throw new Error("Expected a post request");
} else {
log("Reading request");
let available = 0;
let inputStream = new BinaryInputStream(request.bodyInputStream);
while ((available = inputStream.available()) > 0) {
log(inputStream.readBytes(available));
}
}
log("Setting Headers");
response.setHeader("Content-Type", "text/html", false);
response.setStatusLine(request.httpVersion, "200", "OK");
log("Writing body");
response.write(
'<script>"use strict"; let target = opener ? opener : parent; target.postMessage("done", "*");</script>'
);
log("Done");
}
|