Add EscapedPath() and use it for routing-aware redirects and logs#96
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
pawndev
approved these changes
Apr 25, 2026
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
This PR exposes a new method on the
RequestContextthat returns the canonical encoded path the router uses for matching (c.EscapedPath()). It is equivalent toURL.EscapedPath()with hex sequences normalized to uppercase, and is now used acrossServeHTTP,Match,Lookup,serveSubRouter, and theTxnequivalents in place of the internalroutingPath()helper. The internal redirect handlers and theLoggermiddleware also switch to it so that what gets redirected and logged matches exactly what the router routed on.Motivation
The internal redirect handlers (
internalTrailingSlashHandler,internalFixedPathHandler) and theLoggermiddleware previously usedc.Path(), which returnsURL.RawPathif set, otherwise the decodedURL.Path. The router itself routes onEscapedPath()+ uppercase hex normalization, so there was a divergence:/foo%20barwould route on/foo%20barbut redirect to/foo bar/(literal space inLocationheader)./foo%2fbar(lowercase hex) would route on/foo%2Fbarbut redirect to/foo%2fbar.Locationheader and into thepathlog field.Aligning these handlers and the logger on the same canonical form the router operates on removes the inconsistency and makes log entries match the form the router actually decided on.