const CC = Components.Constructor; const BinaryInputStream = CC( "@mozilla.org/binaryinputstream;1", "nsIBinaryInputStream", "setInputStream" ); const RESPONSE_SUCCESS = ` send message, downgraded `; const POST_FORMULAR = `
`; function handleRequest(request, response) { // avoid confusing cache behaviors response.setHeader("Cache-Control", "no-cache", false); let queryString = request.queryString; if (request.scheme === "https" && queryString === "test=1") { response.write(RESPONSE_SUCCESS); return; } if ( request.scheme === "https" && (queryString === "test=2" || queryString === "test=4") ) { // time out request response.processAsync(); return; } if (request.scheme === "http" && queryString === "test=2") { response.write(RESPONSE_SUCCESS); return; } if (queryString === "test=3" || queryString === "test=4") { // send post form response.write(POST_FORMULAR); return; } if (request.method == "POST") { // extract form parameters let body = new BinaryInputStream(request.bodyInputStream); let avail; let bytes = []; while ((avail = body.available()) > 0) { Array.prototype.push.apply(bytes, body.readByteArray(avail)); } let requestBodyContents = String.fromCharCode.apply(null, bytes); response.write(` `); return; } // we should never get here; just in case, return something unexpected response.write("do'h"); }