1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-08 16:53:23 +00:00

fix(filters): make work with dict body parameters, such as aiohttp

Closes https://github.com/kevin1024/vcrpy/issues/398
This commit is contained in:
Ville Skyttä
2021-04-15 22:40:41 +03:00
parent c79a06f639
commit 000f7448a7
2 changed files with 54 additions and 1 deletions

View File

@@ -84,7 +84,17 @@ def replace_post_data_parameters(request, replacements):
replacements = dict(replacements)
if request.method == "POST" and not isinstance(request.body, BytesIO):
if request.headers.get("Content-Type") == "application/json":
if isinstance(request.body, dict):
new_body = request.body.copy()
for k, rv in replacements.items():
if k in new_body:
ov = new_body.pop(k)
if callable(rv):
rv = rv(key=k, value=ov, request=request)
if rv is not None:
new_body[k] = rv
request.body = new_body
elif request.headers.get("Content-Type") == "application/json":
json_data = json.loads(request.body.decode("utf-8"))
for k, rv in replacements.items():
if k in json_data: