summaryrefslogtreecommitdiffstats
path: root/dom/xhr/tests/echo.sjs
blob: e2a1553cb46ba50f5c9855e0d42117c6fc271e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const CC = Components.Constructor;
const BinaryInputStream = CC(
  "@mozilla.org/binaryinputstream;1",
  "nsIBinaryInputStream",
  "setInputStream"
);

function handleRequest(request, response) {
  response.setHeader("Content-Type", "text/plain");
  if (request.method == "GET") {
    response.write(request.queryString);
    return;
  }

  var bodyStream = new BinaryInputStream(request.bodyInputStream);
  var body = "";
  var bodyAvail;
  while ((bodyAvail = bodyStream.available()) > 0) {
    body += String.fromCharCode.apply(
      null,
      bodyStream.readByteArray(bodyAvail)
    );
  }

  response.write(body);
}