browser/devtools/netmonitor/test/sjs_status-codes-test-server.sjs

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 const { classes: Cc, interfaces: Ci } = Components;
michael@0 5
michael@0 6 function handleRequest(request, response) {
michael@0 7 response.processAsync();
michael@0 8
michael@0 9 let params = request.queryString.split("&");
michael@0 10 let status = params.filter((s) => s.contains("sts="))[0].split("=")[1];
michael@0 11
michael@0 12 let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
michael@0 13 timer.initWithCallback(() => {
michael@0 14 // to avoid garbage collection
michael@0 15 timer = null;
michael@0 16 switch (status) {
michael@0 17 case "100":
michael@0 18 response.setStatusLine(request.httpVersion, 101, "Switching Protocols");
michael@0 19 break;
michael@0 20 case "200":
michael@0 21 response.setStatusLine(request.httpVersion, 202, "Created");
michael@0 22 break;
michael@0 23 case "300":
michael@0 24 response.setStatusLine(request.httpVersion, 303, "See Other");
michael@0 25 break;
michael@0 26 case "400":
michael@0 27 response.setStatusLine(request.httpVersion, 404, "Not Found");
michael@0 28 break;
michael@0 29 case "500":
michael@0 30 response.setStatusLine(request.httpVersion, 501, "Not Implemented");
michael@0 31 break;
michael@0 32 }
michael@0 33 response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
michael@0 34 response.write("Hello status code " + status + "!");
michael@0 35 response.finish();
michael@0 36 }, 10, Ci.nsITimer.TYPE_ONE_SHOT); // Make sure this request takes a few ms.
michael@0 37 }

mercurial