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/. */
6 const BinaryInputStream = Components.Constructor(
7 "@mozilla.org/binaryinputstream;1",
8 "nsIBinaryInputStream",
12 function handleRequest(request, response) {
13 response.setStatusLine(request.httpVersion, 200, "Och Aye");
14 response.setHeader("Content-Type", "text/plain; charset=utf-8", false);
17 if (request.method == "POST") {
18 const bodyStream = new BinaryInputStream(request.bodyInputStream);
21 while ((avail = bodyStream.available()) > 0) {
22 body += String.fromCharCode.apply(
24 bodyStream.readByteArray(avail)
29 const contentType = request.hasHeader("content-type")
30 ? request.getHeader("content-type")
33 const bodyOutput = [request.method, contentType, body].join("\n");
34 response.bodyOutputStream.write(bodyOutput, bodyOutput.length);