content/base/test/echo.sjs

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/test/echo.sjs	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,21 @@
     1.4 +const CC = Components.Constructor;
     1.5 +const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1",
     1.6 +                             "nsIBinaryInputStream",
     1.7 +                             "setInputStream");
     1.8 +
     1.9 +function handleRequest(request, response)
    1.10 +{
    1.11 +  response.setHeader("Content-Type", "text/plain");
    1.12 +  if (request.method == "GET") {
    1.13 +     response.write(request.queryString);
    1.14 +     return;
    1.15 +  }
    1.16 +
    1.17 +  var bodyStream = new BinaryInputStream(request.bodyInputStream);
    1.18 +  var body = "";
    1.19 +  var bodyAvail;
    1.20 +  while ((bodyAvail = bodyStream.available()) > 0)
    1.21 +    body += String.fromCharCode.apply(null, bodyStream.readByteArray(bodyAvail));
    1.22 +  
    1.23 +  response.write(body);
    1.24 +}

mercurial