Skip to content

Commit

Permalink
Get body from django proper
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Feys committed Aug 22, 2024
1 parent 96df99a commit 0d8c6ae
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions aikido_firewall/sources/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ def gen_aikido_middleware_function(former__middleware_chain):
"""

def aikido_middleware_function(request):
context = Context(
req=request.META, raw_body=request.body.decode("utf-8"), source="django"
)
# Get a parsed body from Django :
body = request.POST.dict()
if len(body) == 0 and request.content_type == "application/json":
try:
body = json.loads(request.body)
except Exception:
pass
if len(body) == 0:

Check warning on line 27 in aikido_firewall/sources/django.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/django.py#L21-L27

Added lines #L21 - L27 were not covered by tests
# E.g. XML Data
body = request.body

Check warning on line 29 in aikido_firewall/sources/django.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/django.py#L29

Added line #L29 was not covered by tests

context = Context(req=request.META, body=body, source="django")

Check warning on line 31 in aikido_firewall/sources/django.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/django.py#L31

Added line #L31 was not covered by tests
context.set_as_current_context()
request_handler(stage="init")

Expand Down

0 comments on commit 0d8c6ae

Please sign in to comment.