🐛 Fix double stage redirect with V2 custom domain mapping#1440
Open
🐛 Fix double stage redirect with V2 custom domain mapping#1440
Conversation
When a custom domain maps to an API Gateway v2 stage, API Gateway strips
the stage prefix from rawPath before invoking Lambda. But the handler
always set SCRIPT_NAME to /{stage}, causing Django to construct redirect
URLs with a duplicated stage (e.g., /dev/dev/admin/).
Now detects whether rawPath actually starts with the stage prefix.
If not (custom domain case), SCRIPT_NAME is left empty so redirects
produce correct URLs without the stage prefix.
4478ebc to
8d82993
Compare
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.
Summary
Fixes #1409
rawPathbefore invoking LambdaSCRIPT_NAMEto/{stage}, causing Django/Flask to construct redirect URLs with a duplicated stage (e.g.,/dev/dev/admin/)rawPathactually starts with/{stage}— if not (custom domain case),SCRIPT_NAMEis left emptyrawPathincludes the stage) continues to work as beforeTest plan
test_wsgi_v2_custom_domain_no_double_stage— verifies custom domain event produces correct URL without stage prefixtest_wsgi_script_name_on_v2_formatted_event_with_stage_in_pathstill passes (direct API Gateway access)