Skip to content

Conversation

0xrohitgarg
Copy link

Problem

API Gateway v2 events include the stage in rawPath, causing double path prefix in WSGI routing. Requests to {gateway_url}/{stage}/endpoint result in routes like /stage/stage/endpoint instead of /stage/endpoint.

Solution

Replace flawed replace() logic with proper startswith() check to correctly strip script_name from PATH_INFO when present.

Changes

  • Fix path handling in create_wsgi_request() function
  • Use startswith() instead of in check
  • Properly assign the modified path instead of using replace()

Testing

  • Verified fix resolves double prefix issue
  • Confirmed backward compatibility with existing functionality
  • Tested various edge cases (no stage, different stages, etc.)

Fixes #1389

Replace flawed replace() logic with proper startswith() check to ensure
PATH_INFO is correctly stripped of script_name prefix when stage is
included in rawPath for API Gateway v2 events.
@0xrohitgarg 0xrohitgarg marked this pull request as draft September 18, 2025 08:14
@0xrohitgarg 0xrohitgarg marked this pull request as ready for review September 18, 2025 08:39
@0xrohitgarg
Copy link
Author

Hi @monkut, could you please take a look at this PR when you get a chance?

@coveralls
Copy link

Coverage Status

coverage: 72.334% (+0.01%) from 72.32%
when pulling b29972b on 0xrohitgarg:fix/api-gateway-v2-path-prefix
into 2c06c76 on zappa:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue: API Gateway v2 events cause double path prefix in WSGI routing
2 participants