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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
function getFileStream(filename)
{
// Get the location of this sjs file, and then use that to figure out where
// to find where our other files are.
var self = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsIFile);
self.initWithPath(getState("__LOCATION__"));
var file = self.parent;
file.append(filename);
var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
.createInstance(Components.interfaces.nsIFileInputStream);
fileStream.init(file, 1, 0, false);
return fileStream;
}
// stolen from file_blocked_script.sjs
function setGlobalState(data, key) {
x = {
data,
QueryInterface: ChromeUtils.generateQI([]),
};
x.wrappedJSObject = x;
setObjectState(key, x);
}
function getGlobalState(key) {
var data;
getObjectState(key, function(x) {
data = x && x.wrappedJSObject.data;
});
return data;
}
const DELAY_MS = 100;
let gTimer;
function handleRequest(request, response) {
let count = getGlobalState("count");
if (count == null) {
count = 0;
}
if (count > 0) {
response.processAsync();
gTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
gTimer.init(
() => {
response.setStatusLine(request.httpVersion, 304, "Not Modified");
response.finish();
},
DELAY_MS,
Ci.nsITimer.TYPE_ONE_SHOT
);
return;
}
response.setStatusLine(request.httpVersion, 200, "OK");
response.setHeader("Content-Type", "image/gif", false);
var inputStream = getFileStream("1763581-1.gif");
response.bodyOutputStream.writeFrom(inputStream, inputStream.available());
inputStream.close();
count++;
setGlobalState(count, "count");
}
|