Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / devtools / client / netmonitor / test / sjs_method-test-server.sjs
blob4a820f3bccf11f1bfb1024af1b2e5eb4ec805d32
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";
6 const BinaryInputStream = Components.Constructor(
7   "@mozilla.org/binaryinputstream;1",
8   "nsIBinaryInputStream",
9   "setInputStream"
12 function handleRequest(request, response) {
13   response.setStatusLine(request.httpVersion, 200, "Och Aye");
14   response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
16   let body = "";
17   if (request.method == "POST") {
18     const bodyStream = new BinaryInputStream(request.bodyInputStream);
20     let avail = 0;
21     while ((avail = bodyStream.available()) > 0) {
22       body += String.fromCharCode.apply(
23         String,
24         bodyStream.readByteArray(avail)
25       );
26     }
27   }
29   const contentType = request.hasHeader("content-type")
30     ? request.getHeader("content-type")
31     : "";
33   const bodyOutput = [request.method, contentType, body].join("\n");
34   response.bodyOutputStream.write(bodyOutput, bodyOutput.length);