feat(ipv6): support literal IPv6 addresses in 'target' and 'forward' options#1206
feat(ipv6): support literal IPv6 addresses in 'target' and 'forward' options#1206
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds normalization for bracketed IPv6 literal addresses in Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client
participant Proxy as ProxyMiddleware
participant Router as Router
participant IPv6 as normalizeIPv6LiteralTargets
participant Path as applyPathRewrite
participant Upstream as UpstreamServer
Client->>Proxy: incoming HTTP request
Proxy->>Router: applyRouter(req, options)
Router-->>Proxy: resolved target (string/URL/object)
Proxy->>IPv6: normalizeIPv6LiteralTargets(options)
IPv6-->>Proxy: normalized target/forward (host object)
Proxy->>Path: applyPathRewrite(req, options)
Path-->>Proxy: rewritten req.url
Proxy->>Upstream: forward request to normalized target
Upstream-->>Proxy: response
Proxy-->>Client: proxied response
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
commit: |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/unit/utils/ipv6.spec.ts (1)
17-105: Add credentialed IPv6 URL cases to lock auth behavior.Coverage is good overall, but a
user:pass@[::1]case is missing and would protect against credential loss regressions.🧪 Suggested test addition
+ it('should preserve auth when normalizing bracketed IPv6 target string', () => { + const options = { + target: 'http://user:pass@[::1]:8888/api', + }; + + normalizeIPv6LiteralTargets(options); + + expect(options.target).toMatchObject({ + hostname: '::1', + pathname: '/api', + port: '8888', + protocol: 'http:', + search: '', + auth: 'user:pass', + }); + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@test/unit/utils/ipv6.spec.ts` around lines 17 - 105, Add tests to lock auth behavior around normalizeIPv6LiteralTargets: include a credentialed IPv6 URL string (e.g. 'http://user:pass@[::1]:8888/api?foo=bar') as options.target and assert the function does not strip credentials (expect options.target to remain that exact string), and add a credentialed URL object case (const target = new URL('http://user:pass@[::1]:8888/'); options.target = target) and assert normalizeIPv6LiteralTargets leaves the object identity intact (expect options.target toBe(target)); optionally add the same credentialed-string check for options.forward to cover both entry points.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/utils/ipv6.ts`:
- Around line 39-45: normalizeIPv6LiteralTargets() currently returns a target
object with an added auth field (which is wrong); instead, when parsing a string
target (e.g., via new URL(...)) detect embedded credentials using
targetUrl.username and targetUrl.password and set the top-level options.auth =
`${targetUrl.username}:${targetUrl.password}` (omit the colon/password part if
password is empty) before returning the normalized target object; do not add
auth to the returned target object—keep hostname (using stripBrackets),
pathname, port, protocol, and search unchanged and only surface credentials via
options.auth.
---
Nitpick comments:
In `@test/unit/utils/ipv6.spec.ts`:
- Around line 17-105: Add tests to lock auth behavior around
normalizeIPv6LiteralTargets: include a credentialed IPv6 URL string (e.g.
'http://user:pass@[::1]:8888/api?foo=bar') as options.target and assert the
function does not strip credentials (expect options.target to remain that exact
string), and add a credentialed URL object case (const target = new
URL('http://user:pass@[::1]:8888/'); options.target = target) and assert
normalizeIPv6LiteralTargets leaves the object identity intact (expect
options.target toBe(target)); optionally add the same credentialed-string check
for options.forward to cover both entry points.
🪄 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
Run ID: 19679e61-4659-4f64-923b-bb89c0b0751f
📒 Files selected for processing (5)
CHANGELOG.mdsrc/http-proxy-middleware.tssrc/utils/ipv6.tstest/e2e/ipv6.spec.tstest/unit/utils/ipv6.spec.ts
a729809 to
fd2840e
Compare
fd2840e to
1cd6b56
Compare
Add support for literal IPv6 target URLs (with port)
Reference: https://www.ietf.org/rfc/rfc2732.txt
Summary by CodeRabbit
New Features
Tests
Documentation