parsers.py 523 B

12345678910111213141516
  1. import orjson
  2. from django.conf import settings
  3. from django.http import HttpRequest
  4. from ninja.parser import Parser
  5. class EnvelopeParser(Parser):
  6. def parse_body(self, request: HttpRequest):
  7. if request.META.get("CONTENT_TYPE") == "application/x-sentry-envelope":
  8. result = [orjson.loads(line) for line in request.readlines()]
  9. if settings.EVENT_STORE_DEBUG:
  10. print(orjson.dumps(result))
  11. return result
  12. else:
  13. return orjson.loads(request.body)