Skip to content

Fix HTTP request authority port parsing - #16551

Merged
EarthChen merged 1 commit into
apache:3.3from
elaysia-feng:fix/http-authority-port-16547
Oct 28, 2026
Merged

EarthChen merged 1 commit into
apache:3.3from
elaysia-feng:fix/http-authority-port-16547

Conversation

@elaysia-feng

Copy link
Copy Markdown
Contributor

What is the purpose of the change?

Fixes #16547.

DefaultHttpRequest.serverPort() attempted to parse the host portion of an authority as an integer. This change parses the port suffix and avoids treating colons inside bracketed IPv6 addresses as port separators in serverName() and serverPort().

Verification

  • Targeted Maven regression test: 8 tests passed on JDK 21.
  • Before the fix, the same tests reproduced NumberFormatException for IPv4, hostname and IPv6 authorities with ports, and truncation for IPv6 without a port.

Checklist

  • Linked the issue for this change.
  • Explained the behavior and the fix.
  • Added regression tests.
  • GitHub Actions checks have completed.

@codecov-commenter

codecov-commenter commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.93%. Comparing base (843b98b) to head (c38fd02).

Additional details and impacted files
@@             Coverage Diff              @@
##                3.3   #16551      +/-   ##
============================================
+ Coverage     60.90%   60.93%   +0.02%     
- Complexity       15    11765   +11750     
============================================
  Files          1953     1953              
  Lines         89280    89282       +2     
  Branches      13476    13477       +1     
============================================
+ Hits          54376    54404      +28     
+ Misses        29323    29290      -33     
- Partials       5581     5588       +7     
Flag Coverage Δ
integration-tests-java21 32.13% <0.00%> (+0.05%) ⬆️
integration-tests-java8 32.20% <0.00%> (+0.05%) ⬆️
samples-tests-java21 32.14% <0.00%> (+0.01%) ⬆️
samples-tests-java8 29.79% <0.00%> (+0.01%) ⬆️
unit-tests-java11 59.14% <100.00%> (+0.03%) ⬆️
unit-tests-java17 58.65% <100.00%> (+0.05%) ⬆️
unit-tests-java21 58.68% <100.00%> (+0.04%) ⬆️
unit-tests-java25 58.61% <100.00%> (+0.01%) ⬆️
unit-tests-java8 59.16% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 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.

@EarthChen EarthChen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Confirmed the bug: the old serverPort() parsed the part before the colon, so Host: localhost:8013 threw NumberFormatException (reachable via CorsHeaderFilter when an Origin header is present). serverName() also truncated IPv6 hosts such as [2001:db8::1]. getHostPortSeparator handles host, host:port, [v6] and [v6]:port correctly, and the new tests cover these cases.

Non-blocking: Host: host: or a non-numeric port still throws NumberFormatException (existing behavior).

@EarthChen
EarthChen merged commit 7de31de into apache:3.3 Oct 28, 2026
32 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.

[Bug] ServerHttpRequest.getURI() throws NumberFormatException when Host contains an explicit port

3 participants