1/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
2/* vim: set sts=2 sw=2 et tw=80 ft=javascript: */
3"use strict";
4
5/* eslint-disable no-unused-vars */
6
7Cu.import("resource://gre/modules/AppConstants.jsm");
8
9const DELAY = AppConstants.DEBUG ? 4000 : 800;
10
11let nsTimer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
12
13let timer;
14function delay() {
15  return new Promise(resolve => {
16    timer = nsTimer(resolve, DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
17  });
18}
19
20const PARTS = [
21  `<!DOCTYPE html>
22    <html lang="en">
23    <head>
24      <meta charset="UTF-8">
25      <title></title>
26    </head>
27    <body>`,
28  "Lorem ipsum dolor sit amet, <br>",
29  "consectetur adipiscing elit, <br>",
30  "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. <br>",
31  "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. <br>",
32  "Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. <br>",
33  "Excepteur sint occaecat cupidatat non proident, <br>",
34  "sunt in culpa qui officia deserunt mollit anim id est laborum.<br>",
35  `
36    </body>
37    </html>`,
38];
39
40async function handleRequest(request, response) {
41  response.processAsync();
42
43  response.setHeader("Content-Type", "text/html", false);
44  response.setHeader("Cache-Control", "no-cache", false);
45
46  await delay();
47
48  for (let part of PARTS) {
49    response.write(`${part}\n`);
50    await delay();
51  }
52
53  response.finish();
54}
55
56