-
Notifications
You must be signed in to change notification settings - Fork 469
feat: Add a flag to ALBResolver to URL-decode query parameters #7940
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
base: develop
Are you sure you want to change the base?
feat: Add a flag to ALBResolver to URL-decode query parameters #7940
Conversation
|
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
| """Amazon Application Load Balancer (ALB) resolver | ||
| Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are copied from ApiGatewayResolver (except for decode_query_parameters, obviously)
| @override | ||
| def _to_proxy_event(self, event: dict) -> BaseProxyEvent: | ||
| proxy_event = super()._to_proxy_event(event) | ||
| if isinstance(proxy_event, ALBEvent): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should always be the case, but I think mypy would complain if I didn't.
Alternatively, I could just create the ALBEvent here, but if the base method ever changes, that could break.
| @override | ||
| def __init__(self, data: dict[str, Any], json_deserializer: Callable | None = None): | ||
| super().__init__(data, json_deserializer) | ||
| self.decode_query_parameters = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets overridden in ALBResolver._to_proxy_event.
| # Decode the parameter keys and values | ||
| decoded_params = {} | ||
| for k, vals in params.items(): | ||
| decoded_params[unquote(k)] = [unquote(v) for v in vals] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decoded the keys for consistency. That's what it looks like other frameworks do, although I'm not sure it would be useful here.
| @@ -1,4 +1,5 @@ | |||
| import base64 | |||
| import datetime | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the best file for this test? I originally started here, but not sure if something like tests/functional/event_handler/_pydantic/test_api_gateway.py is better.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7940 +/- ##
===========================================
- Coverage 96.72% 96.72% -0.01%
===========================================
Files 278 278
Lines 13607 13626 +19
Branches 1080 1083 +3
===========================================
+ Hits 13162 13180 +18
Misses 327 327
- Partials 118 119 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



Issue number: closes #7621
Summary
From https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html, for ALB requests
This adds a flag to ALBResolver to decode the query parameters before they are validated.
Changes
decode_query_parametersflag toALBResolverinitializer.decode_query_parameterstoALBEvent. This defaults to false.**kwargsargument to theBaseProxyEventinitializers, but didn't love that.ALBResolver._to_proxy_event(overrides the parent method). This calls the parent method, and sets a decode_query_parameters flag on the resulting ALBEvent.User experience
No change to the user experience - default behavior is the same, and users have to opt-in to get the new behavior.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.