blob: f40d5cac97698e816ecf206d98761e1235fea1ed (
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
|
// A 1x1 PNG image.
// Source: https://commons.wikimedia.org/wiki/File:1x1.png (Public Domain)
const IMAGE = atob(
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAA" +
"ACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII="
);
function handleRequest(aRequest, aResponse) {
aResponse.setStatusLine(aRequest.httpVersion, 200);
let key = aRequest.queryString.includes("what=script") ? "script" : "image";
if (aRequest.queryString.includes("result")) {
aResponse.write(getState(key) || 0);
setState(key, "0");
return;
}
if (aRequest.hasHeader("Cookie")) {
let hints = parseInt(getState(key) || 0) + 1;
setState(key, hints.toString());
}
aResponse.setHeader("Set-Cookie", "foopy=1");
if (key == "script") {
aResponse.setHeader("Content-Type", "text/javascript", false);
aResponse.write("42;");
} else {
aResponse.setHeader("Content-Type", "image/png", false);
aResponse.write(IMAGE);
}
}
|