-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to ignore nested parameters in a JSON request body #676
Comments
Interesting idea. Do you happen to have any cases where the key you want to ignore is more than 1 level deep (like If not, that would make things much easier. I think having a single "root" element in a request body ( |
No, I don't have nested keys that are more than one level deep. So for my use case, a single level would be sufficient. |
I could work on a PR on this @JWCook |
That would be great! I don't think the To get you started, the new def normalize_json_body(
original_body: Union[str, bytes],
ignored_parameters: ParamList,
content_root_key: str = None,
) -> Union[str, bytes]:
"""Normalize and filter a request body with serialized JSON data"""
if len(original_body) <= 2 or len(original_body) > MAX_NORM_BODY_SIZE:
return original_body
try:
body = json.loads(decode(original_body))
if content_root_key and isinstance(body, dict) and content_root_key in body:
body[content_root_key] = filter_sort_json(body[content_root_key], ignored_parameters)
else:
body = filter_sort_json(body, ignored_parameters)
return json.dumps(body)
# If it's invalid JSON, then don't mess with it
except (AttributeError, TypeError, ValueError):
logger.debug('Invalid JSON body')
return original_body Then:
Usage would then look like: session = CachedSession(content_root_key='data') Does that sound reasonable to you? |
Is it possible to ignore a nested parameter? For example the data of my requests looks like this:
In this example, I would like to ignore
timestamp
but notkey
when creating the cache key. Yes, I could overwrite thecache_key
function, but feels like this should be part of the library? Maybe like this:data.timestamp
The text was updated successfully, but these errors were encountered: