Skip to content
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

Handling trailing slashes that get omitted in event property #376

Closed
bahoo opened this issue Sep 11, 2022 · 2 comments
Closed

Handling trailing slashes that get omitted in event property #376

bahoo opened this issue Sep 11, 2022 · 2 comments

Comments

@bahoo
Copy link

bahoo commented Sep 11, 2022

Python Version

3.9

Package Version

Latest

Description

Flagging this as somewhere between issue discussion and possible / proposed fix — I noticed in my project that, when requesting a particular URL with a trailing slash, event['requestContext']['http']['path'] coming from AWS will omit the trailing slash. I lost a couple hours digging into redirect loop ( in Django, repeatedly trying to redirect to the admin login screen with its trailing slash in the URL, but never getting there because AWS's event doesn't pass that final slash along ) before finally discovering the issue.

Interestingly, another event property, event['rawPath'] will correctly pass along that trailing slash. Don't know if it is documented anywhere in AWS world why one ( the "raw" path ) would include it, and the other would omit it, but after confirming this discrepancy side by side, I switched to another library which I found does use rawPath and it worked without issue. 💁🏻‍♂️

This feels like AWS's bug to fix ultimately ( either in code for consistency's sake, or at least documentation; ideally both ), and no interest or need in pitting two open source projects against eachother, but using rawPath or some derivative could be a solution here.

Worth noting for my particular instance, Django has a whole APPEND_SLASH setting and middleware to handle this, but the admin redirect logic I mentioned kicks in before this fallback does. Maybe my scenario is too narrow / niche to warrant a code change 💁🏻‍♂️ but the admin's a pretty prominent cornerstone of using Django to begin with, and, anyway anyway ... mostly wanted to get this issue out of just my own brain, and hope this might help save someone a couple hours in the future. 👋🏻

@bahoo
Copy link
Author

bahoo commented Sep 11, 2022

As a trivial demonstration, I created a Lambda function ( Python 3.9 ) that just returns the event exactly as given to it:

import json

def lambda_handler(event, context):
    return event

Deploying & visiting a URL with a trailing slash, e.g. /foo/ shows it off:

trailing-slash

@adamchainz
Copy link
Owner

Thanks for the report. This has been fixed in #426 and released in 2.16.0.

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

No branches or pull requests

2 participants