Skip to content

Commit 3f6c43e

Browse files
authored
Update opera middleware request args parse (#481)
1 parent 6c1f68e commit 3f6c43e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

backend/middleware/opera_log_middleware.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ async def get_request_args(request: Request) -> dict:
133133
args.update({k: v.filename if isinstance(v, UploadFile) else v for k, v in form_data.items()})
134134
else:
135135
if body_data:
136-
json_data = await request.json()
137-
if not isinstance(json_data, dict):
138-
json_data = {
139-
f'{type(json_data)}_to_dict_data': json_data.decode('utf-8')
140-
if isinstance(json_data, bytes)
141-
else json_data
142-
}
143-
args.update(json_data)
136+
content_type = request.headers.get('Content-Type', '').split(';')[0].strip().lower()
137+
if content_type == 'application/json':
138+
json_data = await request.json()
139+
if isinstance(json_data, bytes):
140+
json_data = json_data.decode('utf-8')
141+
args.update(json_data)
142+
else:
143+
args.update({'body': str(body_data)})
144144
return args
145145

146146
@staticmethod

0 commit comments

Comments
 (0)