diff --git a/swh/graph/server/app.py b/swh/graph/server/app.py --- a/swh/graph/server/app.py +++ b/swh/graph/server/app.py @@ -23,8 +23,10 @@ @asynccontextmanager -async def stream_response(request, *args, **kwargs): +async def stream_response(request, content_type='text/plain', + *args, **kwargs): response = aiohttp.web.StreamResponse(*args, **kwargs) + response.content_type = content_type await response.prepare(request) yield response await response.write_eof() @@ -101,7 +103,8 @@ src_node = backend.pid2node[src] it = backend.visit_paths(direction, edges, src_node) - async with stream_response(request) as response: + async with stream_response(request, content_type='application/x-ndjson') \ + as response: async for res_path in it: res_path_pid = [backend.node2pid[n] for n in res_path] line = json.dumps(res_path_pid)