relay: add http request debugger
[relay.git/.git] / relay / remote_actor.py
1 import aiohttp
2 from .database import DATABASE
3 from .http_debug import http_debug
4
5
6 ACTORS = DATABASE.get("actors", {})
7 async def fetch_actor(uri, force=False):
8     if uri in ACTORS and not force:
9         return ACTORS[uri]
10
11     async with aiohttp.ClientSession(trace_configs=[http_debug()]) as session:
12         async with session.get(uri, headers={'Accept': 'application/activity+json'}) as resp:
13             ACTORS[uri] = (await resp.json(encoding='utf-8', content_type=None))
14             DATABASE["actors"] = ACTORS
15             return ACTORS[uri]