-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: listening on IPv6 address not possible #5133
Conversation
Wrap IPv6 addresses in square brackets when making URL in ensureAddress, fixing regression (coder#1582)
119e345
to
55bc52b
Compare
@@ -94,7 +94,8 @@ export const ensureAddress = (server: http.Server, protocol: string): URL | stri | |||
} | |||
|
|||
if (typeof addr !== "string") { | |||
return new URL(`${protocol}://${addr.address}:${addr.port}`) | |||
const host = addr.family === "IPv6" ? `[${addr.address}]` : addr.address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love how simple this is 👏🏼
it("should construct URL with an IPv4 address", async () => { | ||
mockServer.address = () => ({ address: "1.2.3.4", port: 5678, family: "IPv4" }) | ||
const address = ensureAddress(mockServer, "http") | ||
expect(address.toString()).toBe(`http://1.2.3.4:5678/`) | ||
}) | ||
it("should construct URL with an IPv6 address", async () => { | ||
mockServer.address = () => ({ address: "a:b:c:d::1234", port: 5678, family: "IPv6" }) | ||
const address = ensureAddress(mockServer, "http") | ||
expect(address.toString()).toBe(`http://[a:b:c:d::1234]:5678/`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
appreciate you adding more tests as well 👏🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me! Thank you so much 👏🏼
I'll let @code-asher give the final ✅
Codecov Report
@@ Coverage Diff @@
## main #5133 +/- ##
==========================================
+ Coverage 71.73% 71.75% +0.01%
==========================================
Files 30 30
Lines 1684 1685 +1
Branches 374 375 +1
==========================================
+ Hits 1208 1209 +1
Misses 407 407
Partials 69 69
Continue to review full report at Codecov.
|
Wrap IPv6 addresses in square brackets for URL in ensureAddress.
Fixes #1582 (regression)
Thanks ;-)