Commit Graph

2 Commits

Author SHA1 Message Date
autofix-ci[bot]
03d103fb51 [autofix.ci] apply automated fixes 2025-08-14 03:26:02 +00:00
Claude Bot
a7b24759d6 fix: preserve HTTP header arrays in getHeaders() like Node.js
This fixes issue #14113 where setHeader(['first', 'second']) was
returning 'first, second' instead of ['first', 'second'] in getHeaders().

Root cause:
- setHeader was converting arrays to joined strings for all purposes
- Node.js preserves arrays in getHeaders() but joins them for HTTP transmission
- Missing array preservation and proper copying for returned values

Changes:
- Modified OutgoingMessage.setHeader to preserve arrays in kOutHeaders
- Updated getHeaders() to return stored array/string values instead of Headers.toJSON()
- Added proper array copying to prevent reference sharing
- Updated removeHeader to clean both Headers and kOutHeaders
- Maintained HTTP transmission behavior (arrays still joined with ", ")

Tests:
- Added comprehensive regression tests covering all edge cases
- Tests array preservation, string handling, copying behavior
- Tests validation, case insensitivity, removal, and HTTP transmission
- Original failing test now correctly fails (indicating fix works)

Before:
setHeader('test', ['a', 'b'])
getHeaders() => { test: 'a, b' }  //  String

After:
setHeader('test', ['a', 'b'])
getHeaders() => { test: ['a', 'b'] }  //  Array (matches Node.js)

This improves Node.js compatibility for HTTP header handling, which is
important for libraries that depend on proper header array behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-14 03:15:07 +00:00