diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/base/test/delayedServerEvents.sjs | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/base/test/delayedServerEvents.sjs')
-rw-r--r-- | dom/base/test/delayedServerEvents.sjs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/dom/base/test/delayedServerEvents.sjs b/dom/base/test/delayedServerEvents.sjs new file mode 100644 index 000000000..c2d2f5dd9 --- /dev/null +++ b/dom/base/test/delayedServerEvents.sjs @@ -0,0 +1,42 @@ +// this will take strings_to_send.length*500 ms = 5 sec + +var timer = null; +var strings_to_send = ["retry:999999999\ndata\r\n\nda", "ta", ":", "de", "layed1\n\n", + "", + "", + "data:delayed2\n\n", "", ""]; +var resp = null; + +function sendNextString() +{ + if (strings_to_send.length == 0) { + timer.cancel(); + resp.finish(); + timer = null; + resp = null; + return; + } + + resp.write(strings_to_send[0]); + strings_to_send = strings_to_send.splice(1, strings_to_send.length - 1); +} + +function handleRequest(request, response) +{ + var b = 0; + for (var i=0; i < strings_to_send.length; ++i) { + b += strings_to_send[i].length; + } + + response.seizePower(); + response.write("HTTP/1.1 200 OK\r\n") + response.write("Content-Length: " + b + "\r\n"); + response.write("Content-Type: text/event-stream; charset=utf-8\r\n"); + response.write("Cache-Control: no-cache, must-revalidate\r\n"); + response.write("\r\n"); + + resp = response; + + timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); + timer.initWithCallback(sendNextString, 500, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); +} |