diff --git a/kepi/bowler_pub/parsers.py b/kepi/bowler_pub/parsers.py index 843b735..208fa65 100644 --- a/kepi/bowler_pub/parsers.py +++ b/kepi/bowler_pub/parsers.py @@ -5,16 +5,29 @@ # Licensed under the GNU Public License v2. """ -django-rest-framework provides a JSON parser, which -does what we need for parsing ActivityPub. However, -it baulks at the ActivityPub MIME type. So we have a -subclass here with only the accepted MIME type changed. +A custom django-rest-framework parser for ActivityPub. """ -from rest_framework.parsers import JSONParser +import codecs +from django.conf import settings +from rest_framework.parsers import BaseParser -class ActivityParser(JSONParser): +class ActivityParser(BaseParser): """ django-rest-framework parser for application/activity+json. """ media_type = "application/activity+json" + + def parse(self, stream, media_type=None, parser_context=None): + + """ + Traditionally, we'd be parsing the JSON here. But despite + the name, we don't parse the incoming stream here at all. + This is because validate() needs to know the exact content + in order to test the signature. So we just pass it back + as a bytestring. + """ + + result = stream.read() + + return result