Une MAJ de sécurité est nécessaire sur notre version actuelle. Elle sera effectuée lundi 02/08 entre 12h30 et 13h. L'interruption de service devrait durer quelques minutes (probablement moins de 5 minutes).

Commit 39e009c9 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

use line-delimited json streams instead of RFC 7464

(because it is more common)
parent e1c154f9
Pipeline #135938 failed with stages
in 1 second
......@@ -167,7 +167,8 @@ class RateLimiter:
class JsonSeqStreamResponse(StreamResponse):
"""aiohttp response class for streaming json objects
The objects are streamed in the application/json-seq format (RFC 7464).
The stream is line-delimited, i.e: a newline <LF> character is inserted between each JSON
object (and the objects are guaranteed not to contain any newline)
resp = JsonSeqStreamResponse()
......@@ -180,14 +181,11 @@ class JsonSeqStreamResponse(StreamResponse):
def __init__(self, *k, **kw):
super().__init__(*k, **kw)
self.content_type = "application/json-seq"
self.content_type = "application/json"
self.charset = "utf-8"
async def prepare(self, request):
prepared = self.prepared
await super().prepare(request)
if not prepared:
# send periodic nop messages (empty dict) to keep the connection alive
......@@ -200,7 +198,7 @@ class JsonSeqStreamResponse(StreamResponse):
loop = asyncio.get_event_loop()
def keepalive_cb():
except StopIteration:
# it seems that self.write raises StopIteration when the
# connection is closed
......@@ -209,7 +207,7 @@ class JsonSeqStreamResponse(StreamResponse):
loop.call_later(KEEPALIVE_INTERVAL, keepalive_cb)
def send(self, json_object):
self.write(json.dumps(json_object).encode() + b"\n\x1e")
self.write(json.dumps(json_object).encode() + b"\n")
class DoneException(Exception):
// Start an asynchronous long-polling HTTP GET request for streaming a sequence
// of JSON objects (RFC 7464)
// of line-delimited JSON objects
// url: string http url
// on_event: function(event) event callback
......@@ -54,7 +54,7 @@ function json_seq_event_listener(url, on_event=null, on_error=null)
// streaming
while(true) {
var end = req.responseText.indexOf("\x1e", req.offset);
var end = req.responseText.indexOf("\n", req.offset);
if (end < 0) {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment