content/base/test/responseIdentical.sjs
author Gregory Szorc <gps@mozilla.com>
Wed, 28 Jan 2015 13:37:00 -0800
branchMOBILE130_2012050817_RELBRANCH
changeset 120184 c9527b7c0b9a28a3f1209c9488fb16965ed051cd
parent 77844 27c140d86b1b725e3ba5e0d032ab04c54333f0b9
permissions -rw-r--r--
Close old release branch MOBILE130_2012050817_RELBRANCH

const CC = Components.Constructor;
const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
                             "nsIBinaryInputStream",
                             "setInputStream");

// Simply sending back the same data that is received
function handleRequest(request, response)
{
  var body = "";
  var bodyStream = new BinaryInputStream(request.bodyInputStream);
  var bytes = [], avail = 0;
  while ((avail = bodyStream.available()) > 0)
    body += String.fromCharCode.apply(String, bodyStream.readByteArray(avail));

  response.setHeader("Content-Type", "application/octet-stream", false);
  response.write(body);
}