diff options
Diffstat (limited to 'devtools/client/netmonitor/test/sjs_long-polling-server.sjs')
-rw-r--r-- | devtools/client/netmonitor/test/sjs_long-polling-server.sjs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/devtools/client/netmonitor/test/sjs_long-polling-server.sjs b/devtools/client/netmonitor/test/sjs_long-polling-server.sjs new file mode 100644 index 0000000000..2c80149223 --- /dev/null +++ b/devtools/client/netmonitor/test/sjs_long-polling-server.sjs @@ -0,0 +1,35 @@ +"use strict"; + +const key = "blocked-response"; +function setResponse(response) { + setObjectState(key, response); +} + +function getResponse() { + let response; + getObjectState(key, v => { + response = v; + }); + return response; +} + +function handleRequest(request, response) { + const { queryString } = request; + if (!queryString) { + // The default end point will return a blocked response. + // The response object will be stored and will be released + // when "?unblock" is called. + response.processAsync(); + response.setHeader("Content-Type", "text/plain", false); + response.write("Begin...\n"); + setResponse(response); + } else if (queryString == "unblock") { + // unblock the pending response + getResponse().finish(); + setResponse(null); + + // and return synchronously. + response.setHeader("Content-Type", "text/plain"); + response.write("ok"); + } +} |