slow_json.sjs (1965B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 "use strict"; 8 9 // JSON contains a multibyte character 10 const JSON_BYTES_1 = '"\xE3'; 11 const JSON_BYTES_2 = '\x81\x82"'; 12 13 // stolen from file_blocked_script.sjs 14 function setGlobalState(data, key) { 15 const x = { 16 data, 17 QueryInterface: ChromeUtils.generateQI([]), 18 }; 19 x.wrappedJSObject = x; 20 setObjectState(key, x); 21 } 22 23 function getGlobalState(key) { 24 let data; 25 getObjectState(key, function (x) { 26 data = x && x.wrappedJSObject.data; 27 }); 28 return data; 29 } 30 31 function handleRequest(request, response) { 32 if (/^complete/.test(request.queryString)) { 33 // Unblock the previous request. 34 response.setStatusLine(request.httpVersion, 200, "OK"); 35 response.setHeader("Cache-Control", "no-cache", false); 36 response.setHeader("Content-Type", "application/json", false); 37 response.write("true"); // the payload doesn't matter. 38 39 const blockedResponse = getGlobalState("devtools-webconsole"); 40 if (blockedResponse) { 41 blockedResponse.write(JSON_BYTES_2); 42 blockedResponse.finish(); 43 44 setGlobalState(undefined, "devtools-webconsole"); 45 } 46 } else { 47 // Getting the JSON 48 const partial = /^partial/.test(request.queryString); 49 if (!partial) { 50 response.processAsync(); 51 } 52 response.setStatusLine(request.httpVersion, 200, "OK"); 53 response.setHeader("Cache-Control", "no-cache", false); 54 response.setHeader("Content-Type", "application/json; charset=utf8", false); 55 response.write(JSON_BYTES_1); 56 if (!partial) { 57 // Store the response in the global state 58 setGlobalState(response, "devtools-webconsole"); 59 response.bodyOutputStream.flush(); 60 } 61 } 62 }