Skip to content

Commit

Permalink
Bug 1658791: Fix red herring httpd.js error messages. r=nika
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaglione committed Sep 15, 2020
1 parent 0fc9fb5 commit e4514eb
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions dom/base/test/delayedServerEvents.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var strings_to_send = ["retry:999999999\ndata\r\n\nda", "ta", ":", "de", "layed1
"data:delayed2\n\n", "", ""];
var resp = null;

function sendNextString()
{
function sendNextString() {
if (strings_to_send.length == 0) {
timer.cancel();
resp.finish();
Expand All @@ -17,24 +16,25 @@ function sendNextString()
return;
}

resp.write(strings_to_send[0]);
strings_to_send = strings_to_send.splice(1, strings_to_send.length - 1);
try {
resp.write(strings_to_send.shift());
} catch (e) {
timer.cancel();
timer = null;
resp = null;
}
}

function handleRequest(request, response)
{
var b = 0;
for (var i=0; i < strings_to_send.length; ++i) {
b += strings_to_send[i].length;
}

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: " + b + "\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);
Expand Down

0 comments on commit e4514eb

Please sign in to comment.