Tweak AP ctx, and gzip support for HTML resp

This commit is contained in:
Thomas Sileo
2019-08-24 10:41:31 +02:00
parent 784362b532
commit dad3dae988
7 changed files with 188 additions and 128 deletions

View File

@@ -263,6 +263,9 @@ def post_to_outbox(activity: ap.BaseActivity) -> str:
class MicroblogPubBackend(Backend):
"""Implements a Little Boxes backend, backed by MongoDB."""
def ap_context(self) -> Any:
return DEFAULT_CTX
def base_url(self) -> str:
return BASE_URL

View File

@@ -59,7 +59,19 @@ def build_resp(resp):
return resp, headers
def jsonify(**data):
def htmlify(data):
resp, headers = build_resp(data)
return Response(
response=resp,
headers={
**headers,
"Content-Type": "text/html; charset=utf-8",
"Cache-Control": "max-age=0, private, must-revalidate",
},
)
def activitypubify(**data):
if "@context" not in data:
data["@context"] = config.DEFAULT_CTX
resp, headers = build_resp(json.dumps(data))
@@ -68,9 +80,7 @@ def jsonify(**data):
headers={
**headers,
"Cache-Control": "max-age=0, private, must-revalidate",
"Content-Type": "application/json"
if app.debug
else "application/activity+json",
"Content-Type": "application/activity+json",
},
)