fix(adapters): sync raw node req.url with event.url in fromNodeHandler#1433
Conversation
Legacy Node handlers route on the raw req.url, which previously only reflected h3-level rewrites (withBase/mount) through srvx's implicit NodeRequestURL write-back (srvx#118). That channel no longer fires when the pathname needed percent-decode normalization (event.url is a detached clone since #1432), so legacy handlers saw the original un-stripped URL for such requests. Propagate explicitly at the adapter boundary instead: set req.url from the h3 view around the call and restore it once the handler settles. This also unblocks removing the implicit write-back on the srvx side. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesfromNodeHandler URL Sync
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Context
Follow-up to #1432 (percent-decode normalization no longer mutates the shared
_url, fixed in a1cf066).Legacy Node handlers invoked via
fromNodeHandlerroute on the rawreq.url. Until now, h3-level URL rewrites (withBase,mount) only reached that raw request through srvx's implicitNodeRequestURLpathname write-back (srvx#118) — mutation-at-a-distance through the shared parsed URL object.That channel is now half-dead: since a1cf066, requests whose pathname needs percent-decode normalization get a detached
event.urlclone, sowithBasemutations never reach the sharedNodeRequestURL, and legacy handlers saw the original un-stripped URL for such requests (e.g.withBase("/api", fromNodeHandler(m))handedmareq.urlof/api/h%65lloinstead of/hello).Change
Make the propagation explicit at the adapter boundary instead of relying on the shared-object side effect:
fromNodeHandlercomputes h3's view (event.url.pathname + event.url.search); if it differs from the rawreq.url, it swaps it in before calling the legacy handler and restores the original once the handler settles.Behavior for legacy middleware is unchanged vs. the pre-#1432 node behavior (they already received the decoded pathname, since the constructor write-back fired before any handler ran) — except it now also works for percent-encoded paths, which the implicit channel never covered after the clone fix.
This also unblocks srvx dropping the implicit write-back from srvx#118: h3 no longer depends on it, so the raw
IncomingMessage.urlcan stay pristine wire data for every other consumer.Tests
New node-target regression test:
withBase("/api", fromNodeHandler(...))echoingreq.url:/api/hello?q=1→ legacy handler sees/hello?q=1/api/h%65llo→ legacy handler sees/hello(failed before this change)req.urlis restored to/api/h%65lloafter the handler settles (asserted viaonResponse)🤖 Generated with Claude Code
Summary by CodeRabbit