echo.sjs 654 B

12345678910111213141516171819202122
  1. const CC = Components.Constructor;
  2. const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
  3. "nsIBinaryInputStream",
  4. "setInputStream");
  5. function handleRequest(request, response)
  6. {
  7. response.setHeader("Content-Type", "text/plain");
  8. if (request.method == "GET") {
  9. response.write(request.queryString);
  10. return;
  11. }
  12. var bodyStream = new BinaryInputStream(request.bodyInputStream);
  13. var body = "";
  14. var bodyAvail;
  15. while ((bodyAvail = bodyStream.available()) > 0)
  16. body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail));
  17. response.write(body);
  18. }