Skip to content

Commit

Permalink
Merge pull request #93 from sapcc/binary_data_fix
Browse files Browse the repository at this point in the history
avoid binary issue with barbican payload endpoint
  • Loading branch information
notque authored Aug 6, 2024
2 parents 5c1ca8a + ed27520 commit 7b0e437
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions auditmiddleware/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,16 @@ def _create_events(self, target_project, res_id,
events = []

# Check if the response has a JSON body
has_json_body = (response and
(response.content_length or 0) > 0 and
response.text and # Check if response body is not empty
response.content_type == "application/json")
has_json_body = False
if response and (response.content_length or 0) > 0:
if response.content_type == "application/json":
try:
# Attempt to access response.text
response.text
has_json_body = True
except UnicodeDecodeError:
# If we can't decode the text, it's not JSON
has_json_body = False

# check for update operations (POST, PUT, PATCH)
if request.method[0] == 'P' and has_json_body:
Expand Down

0 comments on commit 7b0e437

Please sign in to comment.