1 const CC = Components.Constructor;
3 // Context structure - we need to set this up properly to pass to setObjectState
6 if (iid.equals(Ci.nsISupports)) {
9 throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
13 function setRequest(request) {
14 setObjectState(key, request);
16 function getRequest() {
24 function handleRequest(request, response) {
25 response.processAsync();
26 if (request.queryString == "save") {
27 // Get the context structure and finish the old request
28 getObjectState("context", function (obj) {
29 savedCtx = obj.wrappedJSObject;
30 request = savedCtx.request;
32 response.setHeader("Content-Type", "application/octet-stream", false);
33 response.setHeader("Access-Control-Allow-Origin", "*", false);
34 response.setHeader("Cache-Control", "no-cache", false);
35 response.setStatusLine(request.httpVersion, 200, "OK");
37 const input = request.bodyInputStream;
38 const output = response.bodyOutputStream;
40 while ((bodyAvail = input.available()) > 0) {
41 output.writeFrom(input, bodyAvail);
49 request.queryString == "malformedresult=1" ||
50 request.queryString == "emptyresult=1"
53 request.queryString == "malformedresult=1"
54 ? '{"status":"ok","dat'
55 : '{"status":"ok","data":[]}';
56 response.setHeader("Content-Length", String(jsonOK.length), false);
57 response.setHeader("Content-Type", "application/json", false);
58 response.setHeader("Access-Control-Allow-Origin", "*", false);
59 response.setHeader("Cache-Control", "no-cache", false);
60 response.setStatusLine(request.httpVersion, 200, "OK");
61 response.write(jsonOK, jsonOK.length);
63 } else if (request.queryString == "hangup=1") {
65 } else if (request.queryString == "return400=1") {
66 jsonOK = "{'message':'Bad header:accept-language-stt'}";
67 response.setHeader("Content-Length", String(jsonOK.length), false);
68 response.setHeader("Content-Type", "application/json", false);
69 response.setHeader("Access-Control-Allow-Origin", "*", false);
70 response.setHeader("Cache-Control", "no-cache", false);
71 response.setStatusLine(request.httpVersion, 400, "Bad Request");
72 response.write(jsonOK, jsonOK.length);
75 ctx.wrappedJSObject = ctx;
76 ctx.request = request;
77 setObjectState("context", ctx);
78 jsonOK = '{"status":"ok","data":[{"confidence":0.9085610,"text":"hello"}]}';
79 response.setHeader("Content-Length", String(jsonOK.length), false);
80 response.setHeader("Content-Type", "application/json", false);
81 response.setHeader("Access-Control-Allow-Origin", "*", false);
82 response.setHeader("Cache-Control", "no-cache", false);
83 response.setStatusLine(request.httpVersion, 200, "OK");
84 response.write(jsonOK, jsonOK.length);