Skip to content

Add EscapedPath() and use it for routing-aware redirects and logs#96

Merged
tigerwill90 merged 1 commit into
masterfrom
feat/context-escaped-path
Apr 25, 2026
Merged

Add EscapedPath() and use it for routing-aware redirects and logs#96
tigerwill90 merged 1 commit into
masterfrom
feat/context-escaped-path

Conversation

@tigerwill90
Copy link
Copy Markdown
Collaborator

Summary

This PR exposes a new method on the RequestContext that returns the canonical encoded path the router uses for matching (c.EscapedPath()). It is equivalent to URL.EscapedPath() with hex sequences normalized to uppercase, and is now used across ServeHTTP, Match, Lookup, serveSubRouter, and the Txn equivalents in place of the internal routingPath() helper. The internal redirect handlers and the Logger middleware 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 the Logger middleware previously used c.Path(), which returns URL.RawPath if set, otherwise the decoded URL.Path. The router itself routes on EscapedPath() + uppercase hex normalization, so there was a divergence:

  • A request to /foo%20bar would route on /foo%20bar but redirect to /foo bar/ (literal space in Location header).
  • A request to /foo%2fbar (lowercase hex) would route on /foo%2Fbar but redirect to /foo%2fbar.
  • Decoded sub-delims and non-ASCII bytes leaked into the Location header and into the path log 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
txn.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tigerwill90 tigerwill90 requested a review from pawndev April 25, 2026 20:46
@tigerwill90 tigerwill90 merged commit 13d837f into master Apr 25, 2026
3 of 4 checks passed
@tigerwill90 tigerwill90 deleted the feat/context-escaped-path branch April 25, 2026 21:08
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.

2 participants