Skip to content

fix(handler): preserve latin1 header encoding in WrapHandler#4859

Merged
mcollina merged 1 commit intonodejs:mainfrom
theamodhshetty:codex/fix-wraphandler-latin1
Mar 4, 2026
Merged

fix(handler): preserve latin1 header encoding in WrapHandler#4859
mcollina merged 1 commit intonodejs:mainfrom
theamodhshetty:codex/fix-wraphandler-latin1

Conversation

@theamodhshetty
Copy link
Contributor

Summary

Fixes WrapHandler header/trailer conversion to preserve latin1/isomorphic byte semantics when bridging new handler API -> old handler API.

Today WrapHandler uses Buffer.from(value) (utf-8 default), which can corrupt non-ASCII header bytes when the old API later reads as latin1.

What changed

  • Use latin1 encoding when converting wrapped header keys/values to raw buffers in:
    • onRequestUpgrade
    • onResponseStart
    • onResponseEnd
  • Added a helper to centralize raw header value conversion.
  • Added regression coverage in test/issue-3934.js:
    • WrapHandler preserves latin1 header bytes

Validation

  • node --test test/issue-3934.js
  • npm run lint

Fixes #4797.

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.14%. Comparing base (f734c87) to head (c358b51).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4859   +/-   ##
=======================================
  Coverage   93.13%   93.14%           
=======================================
  Files         109      109           
  Lines       34243    34249    +6     
=======================================
+ Hits        31893    31902    +9     
+ Misses       2350     2347    -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit a95556d into nodejs:main Mar 4, 2026
36 of 37 checks passed
@github-actions github-actions bot mentioned this pull request Mar 12, 2026
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.

WrapHandler translates headers using utf-8 instead of latin1

4 participants