diff options
author | Andrew Godwin | 2022-12-05 20:02:35 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-12-05 20:02:35 -0700 |
commit | 9fe2e6676c32b93023ae301be587a8ab0d93120f (patch) | |
tree | cc1e144ed61785431a98019d6e62f283645bbd40 /core | |
parent | e2d28a4be08ccc629def8c85327b657b0bf36f90 (diff) | |
download | takahe-9fe2e6676c32b93023ae301be587a8ab0d93120f.tar.gz takahe-9fe2e6676c32b93023ae301be587a8ab0d93120f.tar.bz2 takahe-9fe2e6676c32b93023ae301be587a8ab0d93120f.zip |
Add a middleware to detect LD Accept headers
Diffstat (limited to 'core')
-rw-r--r-- | core/middleware.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/core/middleware.py b/core/middleware.py index 274f672..de35c4c 100644 --- a/core/middleware.py +++ b/core/middleware.py @@ -6,6 +6,25 @@ from core import sentry from core.models import Config +class AcceptMiddleware: + """ + Detects any Accept headers signifying a fellow AP server is trying to get JSON. + """ + + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + accept = request.headers.get("accept", "text/html").lower() + request.ap_json = ( + "application/json" in accept + or "application/ld" in accept + or "application/activity" in accept + ) + response = self.get_response(request) + return response + + class ConfigLoadingMiddleware: """ Caches the system config every request |