Skip to content

fix: preserve percent-encoded req.url in app event handler#1355

Merged
pi0 merged 5 commits intoh3js:v1from
sergioazoc:fix/preserve-encoded-req-url
Mar 22, 2026
Merged

fix: preserve percent-encoded req.url in app event handler#1355
pi0 merged 5 commits intoh3js:v1from
sergioazoc:fix/preserve-encoded-req-url

Conversation

@sergioazoc
Copy link
Copy Markdown

Summary

  • Fixes createAppEventHandler overwriting event.node.req.url with the decoded path, which breaks HTTP proxies forwarding requests with percent-encoded UTF-8 characters.
  • Keeps a _rawLayerPath derived from the original encoded URL for req.url, while event._path continues using the decoded form for internal routing.
  • Adds test verifying req.url stays percent-encoded while event.path is decoded.

Test plan

  • All 355 existing tests pass
  • New test: req.url preserves percent-encoded UTF-8 characters
  • Verified against Nuxt 4.4.2 + Nitro 2.13.2 dev server — OG image URLs with accented chars now return 200 instead of 400

Closes #1354

`createAppEventHandler` was writing the decoded path (from `_decodePath`)
back to `event.node.req.url`. This breaks HTTP proxies (e.g. Nitro dev
server using httpxy) that forward `req.url` directly — they would send
raw UTF-8 bytes instead of percent-encoded form, causing 400 Bad Request
from downstream servers.

Keep a separate `_rawLayerPath` derived from the original encoded URL and
use it for `req.url`, while `event._path` continues using the decoded
form for h3 internal routing and security checks.

Closes h3js#1354
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 21, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 07f5b762-d82b-461d-a7c7-22b85536c4e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0
Copy link
Copy Markdown
Member

pi0 commented Mar 21, 2026

Thanks for PR. can you please also check failing CI 🙏🏼

@pi0 pi0 merged commit 51ca9b3 into h3js:v1 Mar 22, 2026
1 check passed
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