Skip to content

feat: derive host from hostname for plain object targets and bracket IPv6 literals#136

Merged
pi0 merged 4 commits into
unjs:mainfrom
bjohansebas:ipv6
May 19, 2026
Merged

feat: derive host from hostname for plain object targets and bracket IPv6 literals#136
pi0 merged 4 commits into
unjs:mainfrom
bjohansebas:ipv6

Conversation

@bjohansebas
Copy link
Copy Markdown
Contributor

@bjohansebas bjohansebas commented May 11, 2026

When a proxy target is passed as a plain ProxyTargetDetailed object containing only hostname / port / protocol (no host), setupOutgoing leaves outgoing.host as undefined. The subsequent changeOrigin branch then constructs a malformed Host header:

Host: undefined:<port>

For IPv6 literals (e.g. hostname: "::1"), the problem is if a consumer tries to derive host manually, RFC 3986 §3.2.2 requires brackets in URI host syntax that aren't present in the bare hostname.

Unblock: webpack/webpack-dev-server#5663

Summary by CodeRabbit

  • Bug Fixes

    • Host headers are now derived reliably from hostname and port, with correct RFC 3986-compliant bracketed formatting for IPv6 to prevent malformed Host values.
  • Tests

    • Added coverage verifying Host header derivation, IPv6 formatting/bracketing behavior, default port handling, and preservation of incoming Host when changeOrigin is disabled.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 126178ee-cbac-443d-a975-bf358e42a2d4

📥 Commits

Reviewing files that changed from the base of the PR and between 06165ac and 489d4ec.

📒 Files selected for processing (1)
  • test/_utils.test.ts

📝 Walkthrough

Walkthrough

setupOutgoing now builds outgoing.host from outgoing.hostname and outgoing.port when host is missing, adding RFC 3986 brackets for IPv6 literals; tests cover IPv4, IPv6, default-port behavior, and changeOrigin=false preservation.

Changes

Host Header Derivation from Hostname and Port

Layer / File(s) Summary
setupOutgoing Host Derivation
src/_utils.ts
setupOutgoing sets outgoing.host by combining outgoing.hostname and outgoing.port when outgoing.host is undefined, detecting IPv6 literals and wrapping them in brackets per RFC 3986.
Tests for Host Header Derivation
test/_utils.test.ts
Added tests validating Host header composition from hostname:port, IPv6 bracketing and non-double-bracketing, use of protocol default port when port is omitted, and that changeOrigin: false preserves the incoming Host.

🎯 3 (Moderate) | ⏱️ ~20 minutes

"I hopped through headers, small and fleet,
Bracketed IPv6 so hosts look neat,
From hostname and port I weave the line,
No malformed Host — the request's fine! 🐇"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main changes: deriving host from hostname for plain object targets and bracketing IPv6 literals per RFC 3986.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@bjohansebas
Copy link
Copy Markdown
Contributor Author

hi @pio

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.93%. Comparing base (6e251d9) to head (7a36d89).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
+ Coverage   94.91%   94.93%   +0.02%     
==========================================
  Files           8        8              
  Lines         786      790       +4     
  Branches      320      324       +4     
==========================================
+ Hits          746      750       +4     
  Misses         35       35              
  Partials        5        5              

☔ 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
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thnx and sorry for delay on this!

@pi0 pi0 merged commit 32193b2 into unjs:main May 19, 2026
5 checks 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