Add custom middleware to strip slashes #422
Merged
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.
Pull request checklist:
CHANGELOG.md
was updated, if applicableDescription
Heavily inspired by the middleware provided by chi. The new custom solution also strips url-encoded trailing slashes.
This for example fixes mobile tiktok links (
https://vm.tiktok.com/ZMY8my6vq/
), which are shared with a trailing slash by default. They didn't match to the link resolver router before the changes in this pr.EDIT
After some investigation, the true cause for this problem has been found. The middleware from chi uses the decoded URL to strip slashes. So it correctly strips both trailing "/" and trailing "%2F". It then uses the decoded URL to determine the correct handler for the route. Requests to
/link_resolver/{url}
now contain a URL that is not encoded anymore, and chi fails to find the proper handler. The new middleware fixes this by assigning the encoded URL to the correct parameter.