bug1047663_worker.sjs 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const WORKER_1 = `
  6. "use strict";
  7. self.onmessage = function () {
  8. postMessage("one");
  9. };
  10. `;
  11. const WORKER_2 = `
  12. "use strict";
  13. self.onmessage = function () {
  14. postMessage("two");
  15. };
  16. `;
  17. function handleRequest(request, response) {
  18. let count = getState("count");
  19. if (count === "") {
  20. count = "1";
  21. }
  22. // This header is necessary for the cache to trigger.
  23. response.setHeader("Cache-control", "max-age=3600");
  24. // If this is the first request, return the first source.
  25. if (count === "1") {
  26. response.write(WORKER_1);
  27. setState("count", "2");
  28. }
  29. // For all subsequent requests, return the second source.
  30. else {
  31. response.write(WORKER_2);
  32. }
  33. }