Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7066208
D2244.id7748.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D2244.id7748.diff
View Options
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
@@ -22,9 +22,14 @@
from async_generator import asynccontextmanager # type: ignore
+JSON_CT = 'application/json'
+NDJSON_CT = 'application/x-ndjson' # see http://ndjson.org/
+
+
@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()
@@ -48,7 +53,7 @@
async def stats(request):
stats = request.app['backend'].stats()
- return aiohttp.web.Response(body=stats, content_type='application/json')
+ return aiohttp.web.Response(body=stats, content_type=JSON_CT)
def get_simple_traversal_handler(ttype):
@@ -101,7 +106,7 @@
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=NDJSON_CT) 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)
@@ -121,8 +126,7 @@
src_node = backend.pid2node[src]
cnt = await loop.run_in_executor(
None, backend.count, ttype, direction, edges, src_node)
- return aiohttp.web.Response(body=str(cnt),
- content_type='application/json')
+ return aiohttp.web.Response(body=str(cnt), content_type=JSON_CT)
return count
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Nov 5 2024, 1:15 AM (11 w, 17 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3230507
Attached To
D2244: REST server: set content-type to text or ndjson where appropriate
Event Timeline
Log In to Comment