Skip to content

Commit

Permalink
Try-except and fetch cookies for flask
Browse files Browse the repository at this point in the history
  • Loading branch information
Wout Feys committed Sep 3, 2024
1 parent 7659e3d commit ad1f2b5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions aikido_firewall/sources/flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@ def aikido_view_func(*args, **kwargs):

req = request_ctx.request
# Set body :
context = get_current_context()
if context:
if req.is_json:
context.body = req.get_json()
elif req.form:
context.body = req.form
else:
context.body = req.data.decode("utf-8")
context.set_as_current_context()
try:
context = get_current_context()
if context:
if req.is_json:
context.body = req.get_json()
elif req.form:
context.body = req.form

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

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/flask.py#L25-L31

Added lines #L25 - L31 were not covered by tests
else:
context.body = req.data.decode("utf-8")
context.cookies = req.cookies.to_dict()
context.set_as_current_context()

Check warning on line 35 in aikido_firewall/sources/flask.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/flask.py#L33-L35

Added lines #L33 - L35 were not covered by tests

pre_response = request_handler(stage="pre_response")
pre_response = request_handler(stage="pre_response")
except Exception as e:
logger.debug("Exception in aikido's view function : %s", e)

Check warning on line 39 in aikido_firewall/sources/flask.py

View check run for this annotation

Codecov / codecov/patch

aikido_firewall/sources/flask.py#L37-L39

Added lines #L37 - L39 were not covered by tests
if pre_response:
return pre_response[0], pre_response[1]
try:
Expand Down

0 comments on commit ad1f2b5

Please sign in to comment.