summaryrefslogtreecommitdiffstats
path: root/dom/base/test/delayedServerEvents.sjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/test/delayedServerEvents.sjs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/test/delayedServerEvents.sjs')
-rw-r--r--dom/base/test/delayedServerEvents.sjs56
1 files changed, 56 insertions, 0 deletions
diff --git a/dom/base/test/delayedServerEvents.sjs b/dom/base/test/delayedServerEvents.sjs
new file mode 100644
index 0000000000..cfc1bca508
--- /dev/null
+++ b/dom/base/test/delayedServerEvents.sjs
@@ -0,0 +1,56 @@
+// 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) {
+ timer.cancel();
+ resp.finish();
+ timer = null;
+ resp = null;
+ return;
+ }
+
+ try {
+ resp.write(strings_to_send.shift());
+ } catch (e) {
+ timer.cancel();
+ timer = null;
+ resp = null;
+ }
+}
+
+function handleRequest(request, response) {
+ var bytes = strings_to_send.reduce((len, s) => len + s.length, 0);
+
+ response.seizePower();
+ response.write("HTTP/1.1 200 OK\r\n");
+ response.write(`Content-Length: ${bytes}\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
+ );
+}