Repository navigation
Conversation
…verLocal HttpProxyEvent.from_asgi only copied method, path, headers, body and query string, so the request context fell back to a stub with only stage, requestId and http method/path, and HttpProxyEvent had no request_context property. Handlers reading source_ip or user_agent from the request context raised AttributeError under uvicorn. Fill the request context from the ASGI scope: the source IP from scope client and the user agent from the user-agent header, and expose it through a request_context property on the local event. Refs aws-powertools#8802 Signed-off-by: Ajey Awasthi <115537579+dropps07@users.noreply.github.com>
|
Author
|
Hi @leandrodamascena, the PR is ready for review whenever you have a moment. Please let me know if it needs anything added, removed or changed. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #8802
Summary
Changes
Fill request_context from the ASGI scope so handlers running under uvicorn read the same fields they read in Lambda. Fixes #8802.
from_asgi fills the source IP from the scope client address and the user agent from the user-agent header, and exposes it through a request_context property on HttpProxyEvent. Lambda-specific fields stay as they are today.
The v2.0 local event shape option from the issue is not included. Leandro's scope for this issue is the request_context fill only. Happy to follow up on the event shape option separately if he wants it.
User experience
Before this change, handlers running under uvicorn that read the source IP or user agent from the request context raised AttributeError, because the request context was not filled from the ASGI scope. After this change, those handlers read the same fields they read in Lambda, with the source IP taken from the ASGI scope client address and the user agent taken from the user-agent header.
Verification
Added 2 new tests through HttpResolverLocal with a realistic ASGI scope. All 69 HTTP resolver tests pass. Negative control: both new tests fail on unfixed code with AttributeError, the exact bug from the issue. Ruff format check, ruff check and mypy are clean on the changed file. Not verified: no live uvicorn run and no full make pr run.
Acknowledgement: This work was AI-assisted. I verified it myself by running the repo's pytest suite for the HTTP resolver, plus ruff and mypy on the changed file. I did not run a live uvicorn server or the full make pr pipeline.
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.