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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
const TIMEOUT_INTERVAL_MS = 100;
function handleRequest(request, response) {
// Allow us to asynchronously construct the response with timeouts
// rather than forcing us to make the whole thing in one call. See
// bug 396226.
response.processAsync();
// Figure out whether the client wants to load the image, or just
// to tell us to finish the previous load
var query = {};
request.queryString.split("&").forEach(function (val) {
var [name, value] = val.split("=");
query[name] = unescape(value);
});
if (query.continue == "true") {
// Debugging information so we can figure out the hang
dump("file_IconTestServer.js DEBUG - Got continue command\n");
// Get the context structure and finish the old request
getObjectState("context", function (obj) {
// magic or goop, depending on how you look at it
savedCtx = obj.wrappedJSObject;
// Write the rest of the data
savedCtx.ostream.writeFrom(
savedCtx.istream,
savedCtx.istream.available()
);
// Close the streams
savedCtx.ostream.close();
savedCtx.istream.close();
// Finish off 'the old response'
savedCtx.response.finish();
});
// Finish off 'the current response'
response.finish();
return;
}
// Debugging information so we can figure out the hang
dump("file_IconTestServer.js DEBUG - Got initial request\n");
// Context structure - we need to set this up properly to pass to setObjectState
var ctx = {
QueryInterface: function (iid) {
if (iid.equals(Ci.nsISupports)) {
return this;
}
throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
},
};
ctx.wrappedJSObject = ctx;
// Save the response
ctx.response = response;
// We're serving up a png
response.setHeader("Content-Type", "image/png", false);
// Get the output stream
ctx.ostream = response.bodyOutputStream;
// Ugly hack, but effective - copied from dom/media/test/contentDuration1.sjs
var pngFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("CurWorkD", Ci.nsIFile);
var paths = "tests/layout/generic/test/file_Dolske.png";
var split = paths.split("/");
for (var i = 0; i < split.length; ++i) {
pngFile.append(split[i]);
}
// Get an input stream for the png data
ctx.istream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
Ci.nsIFileInputStream
);
ctx.istream.init(pngFile, -1, 0, 0);
// Write the first 10 bytes, which is just boilerplate/magic bytes
ctx.ostream.writeFrom(ctx.istream, 10);
// Save the context structure for retrieval when we get pinged
setObjectState("context", ctx);
// Now we play the waiting game...
// Debugging information so we can figure out the hang
dump("file_IconTestServer.js DEBUG - Playing the waiting game\n");
}
|