michael@0: const CC = Components.Constructor; michael@0: const BinaryInputStream = CC("@mozilla.org/binaryinputstream;1", michael@0: "nsIBinaryInputStream", michael@0: "setInputStream"); michael@0: michael@0: function handleRequest(request, response) michael@0: { michael@0: if (request.hasHeader("Content-Type")) michael@0: response.setHeader("Result-Content-Type", michael@0: request.getHeader("Content-Type")); michael@0: michael@0: response.setHeader("Content-Type", "text/plain; charset=ISO-8859-1"); michael@0: michael@0: var body = new BinaryInputStream(request.bodyInputStream); michael@0: var avail; michael@0: var bytes = []; michael@0: while ((avail = body.available()) > 0) michael@0: Array.prototype.push.apply(bytes, body.readByteArray(avail)); michael@0: michael@0: var data = String.fromCharCode.apply(null, bytes); michael@0: response.setHeader("Result-Content-Length", "" + data.length); michael@0: if (data.indexOf("TEST_REDIRECT_STR") >= 0) { michael@0: var newURL = "http://" + data.split("&url=")[1]; michael@0: response.setStatusLine(null, 307, "redirect"); michael@0: response.setHeader("Location", newURL, false); michael@0: } michael@0: else { michael@0: response.write(data); michael@0: } michael@0: }