Skip to content

Fix handling default ports from URL#1491

Merged
w666 merged 1 commit into
masterfrom
fix-1488-fix-url-parse
May 13, 2026
Merged

Fix handling default ports from URL#1491
w666 merged 1 commit into
masterfrom
fix-1488-fix-url-parse

Conversation

@w666
Copy link
Copy Markdown
Collaborator

@w666 w666 commented May 8, 2026

Close #1488

Summary by CodeRabbit

  • Bug Fixes
    • Preserve explicitly specified ports in request Host headers so non-standard ports remain intact instead of reverting to protocol defaults.
  • Tests
    • Added tests to verify Host header behavior with and without explicit ports (including non-default ports).
  • Chores
    • Updated build configuration to include Node types for the TypeScript compiler.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

The PR updates Host header construction to preserve explicitly provided ports from raw URLs (including IPv6), adds helpers to extract explicit ports and bracket IPv6 hostnames, adds a unit test verifying default ports are omitted and explicit ports preserved, and adds types: ["node"] to tsconfig.

Changes

Host Header Port Handling

Layer / File(s) Summary
Port Extraction Helper
src/http.ts
getPortFromUrl(url: string) parses raw URL authority and returns a numeric port only when explicitly present, handling IPv6 bracket notation.
IPv6 Bracketing Helper
src/http.ts
Added bracketIPv6(hostname: string) to ensure IPv6 literals are bracketed when composing Host headers.
Host Header Construction
src/http.ts
HttpClient.buildRequest uses the new helper to detect explicit ports and sets Host to hostname:port (with IPv6 brackets) when present, otherwise falls back to `curl.host
Tests
test/client-customHttp-test.js
New test verifies Host header omits default protocol ports (443/80) and preserves explicit non-default ports (e.g., :8443).
TS Config
tsconfig.json
Added types: ["node"] to compilerOptions alongside existing skipLibCheck: true.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tiny port was hiding near,
If default — hush — it won't appear.
But if you spell it, clear and loud,
We'll keep it in the Host, proud.
Bracketed IPv6 sings aloud.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The tsconfig.json change adding 'types: ["node"]' appears unrelated to fixing URL/port handling in the HTTP client and may be an out-of-scope configuration change. Clarify whether the tsconfig.json change is necessary for this fix; if not, remove it to keep the PR focused on the port handling regression.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix handling default ports from URL' directly relates to the main change: updating port/Host header construction to preserve explicitly provided ports while removing dependence on protocol defaults.
Linked Issues check ✅ Passed The PR fixes URL parsing and default port handling to resolve the regression in createClientAsync that produced empty URIs. Changes to buildRequest's Host header construction and port extraction align with fixing the reported 'Invalid WSDL URL' error.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-1488-fix-url-parse

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
test/client-customHttp-test.js (1)

120-131: ⚡ Quick win

Extend this test with explicit default-port and IPv6 cases.

To lock the regression down, add cases for explicitly specified default ports and IPv6 literals.

Proposed test additions
 it('should not append default ports to Host header', function () {
   var client = new httpClient();

   var httpsReq = client.buildRequest('https://example.com/service?wsdl', null);
   assert.equal(httpsReq.headers.Host, 'example.com');

   var httpReq = client.buildRequest('http://example.com/service?wsdl', null);
   assert.equal(httpReq.headers.Host, 'example.com');

   var explicitPortReq = client.buildRequest('https://example.com:8443/service?wsdl', null);
   assert.equal(explicitPortReq.headers.Host, 'example.com:8443');
+
+  var explicitHttpsDefaultPortReq = client.buildRequest('https://example.com:443/service?wsdl', null);
+  assert.equal(explicitHttpsDefaultPortReq.headers.Host, 'example.com:443');
+
+  var explicitHttpDefaultPortReq = client.buildRequest('http://example.com:80/service?wsdl', null);
+  assert.equal(explicitHttpDefaultPortReq.headers.Host, 'example.com:80');
+
+  var explicitIpv6PortReq = client.buildRequest('https://[2001:db8::1]:8443/service?wsdl', null);
+  assert.equal(explicitIpv6PortReq.headers.Host, '[2001:db8::1]:8443');
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/client-customHttp-test.js` around lines 120 - 131, Extend the existing
test "should not append default ports to Host header" by adding assertions for
an explicitly specified default port and IPv6 literals: call client.buildRequest
with 'https://example.com:443/service?wsdl' and assert its headers.Host is
'example.com:443' (explicit default port preserved), then test IPv6 addresses
like 'http://[::1]/service?wsdl' expecting headers.Host '[::1]' and
'http://[::1]:8080/service?wsdl' expecting headers.Host '[::1]:8080'; reference
the httpClient constructor and client.buildRequest in the same test block to add
these cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/http.ts`:
- Around line 85-87: The Host header construction can produce malformed IPv6
addresses when a port is present; update the logic that sets host (where
getPortFromUrl(rurl) and curl.hostname are used) to bracket IPv6 addresses
before appending the port. Add a small helper (e.g., bracketIPv6(hostname)) that
returns hostname unchanged for IPv4/hostname or already-bracketed values, and
returns `[hostname]` for raw IPv6 literals, then use
`${bracketIPv6(curl.hostname)}:${port}` when port is present; keep the existing
fallback of curl.host || curl.hostname when no explicit port is extracted.

---

Nitpick comments:
In `@test/client-customHttp-test.js`:
- Around line 120-131: Extend the existing test "should not append default ports
to Host header" by adding assertions for an explicitly specified default port
and IPv6 literals: call client.buildRequest with
'https://example.com:443/service?wsdl' and assert its headers.Host is
'example.com:443' (explicit default port preserved), then test IPv6 addresses
like 'http://[::1]/service?wsdl' expecting headers.Host '[::1]' and
'http://[::1]:8080/service?wsdl' expecting headers.Host '[::1]:8080'; reference
the httpClient constructor and client.buildRequest in the same test block to add
these cases.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1d891523-f4a4-4eb7-b427-96e0a30632e9

📥 Commits

Reviewing files that changed from the base of the PR and between 67febcc and ce75134.

📒 Files selected for processing (2)
  • src/http.ts
  • test/client-customHttp-test.js

Comment thread src/http.ts
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 11, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 1 unresolved review comment.

Files modified:

  • src/http.ts
  • tsconfig.json

Commit: 1f25ea6979ccac1fcf7bdac1fa79ecadff3777e8

The changes have been pushed to the fix-1488-fix-url-parse branch.

Time taken: 2m 31s

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/http.ts`:
- Around line 41-43: The getPortFromUrl function currently accepts any all-digit
port string and returns it; change its validation to parse the extracted port
into a number and only return it if it is an integer within the 0–65535 range,
otherwise return an empty string; apply the same numeric-range guard to the
other identical port-extraction branch in the file (the second occurrence around
the Host/hostPort handling) so both explicit-port paths enforce 0..65535.

In `@tsconfig.json`:
- Around line 16-22: The tsconfig change disables TypeScript strictness globally
by setting "strict", "noImplicitAny", "strictNullChecks", "strictFunctionTypes",
"strictBindCallApply", "strictPropertyInitialization", and "noImplicitThis" to
false; revert these toggles to their prior baseline (restore "strict": true or
remove the overridden flags) so the PR does not relax type-safety—locate and
update the entries for "strict", "noImplicitAny", "strictNullChecks",
"strictFunctionTypes", "strictBindCallApply", "strictPropertyInitialization",
and "noImplicitThis" in tsconfig.json to match the repository's strictness
baseline.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 18a6c95f-abec-45b4-ae09-87c4b4ffb0c1

📥 Commits

Reviewing files that changed from the base of the PR and between ce75134 and 1f25ea6.

📒 Files selected for processing (2)
  • src/http.ts
  • tsconfig.json

Comment thread src/http.ts
Comment thread tsconfig.json Outdated
Comment thread src/http.ts
@w666 w666 force-pushed the fix-1488-fix-url-parse branch from 1f25ea6 to a678779 Compare May 13, 2026 20:46
@w666 w666 force-pushed the fix-1488-fix-url-parse branch from a678779 to 2982208 Compare May 13, 2026 20:49
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/http.ts (1)

41-43: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Validate extracted port range before using it in Host header.

getPortFromUrl accepts any numeric string, including invalid ports like 99999. The past review comment on this issue remains unaddressed. Add a range check (0..65535) so only valid explicit ports are preserved.

🛡️ Suggested guard
 function getPortFromUrl(url: string): string {
+  const isValidPort = (value: string): boolean => {
+    if (!/^\d+$/.test(value)) return false;
+    const n = Number(value);
+    return Number.isInteger(n) && n >= 0 && n <= 65535;
+  };
+
   // Capture the authority section (everything between :// and the first /?#)
   const authorityMatch = /^[a-z][a-z0-9+.-]*:\/\/([^/?#]+)/i.exec(url);
   if (!authorityMatch) {
     return '';
   }
   
   const hostPort = authorityMatch[1];
   
   // IPv6 address: [::1] or [::1]:port
   if (hostPort.startsWith('[')) {
     const bracketEnd = hostPort.indexOf(']');
     if (bracketEnd !== -1 && hostPort[bracketEnd + 1] === ':') {
       const port = hostPort.slice(bracketEnd + 2);
-      return /^\d+$/.test(port) ? port : '';
+      return isValidPort(port) ? port : '';
     }
     return '';
   }
   
   // IPv4 / hostname: host or host:port
   const colonIndex = hostPort.lastIndexOf(':');
   if (colonIndex === -1) {
     return '';
   }
   const port = hostPort.slice(colonIndex + 1);
-  return /^\d+$/.test(port) ? port : '';
+  return isValidPort(port) ? port : '';
 }

Also applies to: 52-53

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/http.ts` around lines 41 - 43, The extracted port string returned by
getPortFromUrl (where port is computed via hostPort.slice(bracketEnd + 2)) is
currently only checked with /^\d+$/.test; change this to parse the numeric value
(e.g., Number or parseInt) and enforce 0 <= portNum <= 65535, returning '' for
out-of-range or non-numeric values so only valid explicit ports are preserved;
apply the same numeric+range check to the other similar extraction branch that
currently uses /^\d+$/.test to ensure consistent validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tsconfig.json`:
- Line 12: The tsconfig change replaced skipLibCheck with "types": ["node"],
which prevents TypeScript from loading other ambient type packages (e.g.,
`@types/debug`, `@types/sax`, `@types/formidable`, `@types/whatwg-mimetype`) used across
files like wsdl/index.ts, wsdl/elements.ts, http.ts, client.ts and utils.ts; fix
by either restoring skipLibCheck: true and removing the "types" option, or
update the "types" array to include the missing ambient packages ("node",
"debug", "sax", "formidable", "whatwg-mimetype") so those `@types/`* definitions
are picked up during compilation.

---

Duplicate comments:
In `@src/http.ts`:
- Around line 41-43: The extracted port string returned by getPortFromUrl (where
port is computed via hostPort.slice(bracketEnd + 2)) is currently only checked
with /^\d+$/.test; change this to parse the numeric value (e.g., Number or
parseInt) and enforce 0 <= portNum <= 65535, returning '' for out-of-range or
non-numeric values so only valid explicit ports are preserved; apply the same
numeric+range check to the other similar extraction branch that currently uses
/^\d+$/.test to ensure consistent validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 52dbe055-5480-4b76-975f-aa443a382277

📥 Commits

Reviewing files that changed from the base of the PR and between 1f25ea6 and a678779.

📒 Files selected for processing (3)
  • src/http.ts
  • test/client-customHttp-test.js
  • tsconfig.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/client-customHttp-test.js

Comment thread tsconfig.json
@w666 w666 merged commit f74f6bc into master May 13, 2026
3 of 4 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.

Invalid WSDL URL when createClientAsync

2 participants