Make --host take an optional IP address to bind to#265
Merged
dubadub merged 1 commit intocooklang:mainfrom Feb 18, 2026
Merged
Conversation
Also support IPv6 with no arg by binding :: instead of 0.0.0.0
7e9b99c to
a496cf1
Compare
pvsr
commented
Feb 18, 2026
| SocketAddr::from(([127, 0, 0, 1], args.port)) | ||
| let addr = match args.host { | ||
| Some(Some(addr)) => addr, | ||
| Some(None) => "::".parse()?, |
Contributor
Author
There was a problem hiding this comment.
An alternative option that's verbose but more consistent:
Suggested change
| Some(None) => "::".parse()?, | |
| Some(None) => [0, 0, 0, 0, 0, 0, 0, 0].into(), |
dubadub
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This allows the server to accept connections on just a specific IP address. I also changed the default address when the argument isn't provided from
0.0.0.0to the IPv6 equivalent of::, which means the server will accept connections on both IPv4 and IPv6 addresses instead of just IPv4. The default when--hostis not provided remains127.0.0.1, as the IPv6 equivalent of::1doesn't cover both.For each configuration I tested connectivity on five addresses:
127.0.0.1,::1,localhost, and my IPv4 and IPv6 LAN addresses, and that--openbrought me to a working page.Before
cook server: only requests to127.0.0.1andlocalhostsucceedcook server --host:::1and IPv6 LAN address fail, the rest succeedAfter
cook server: only requests to127.0.0.1andlocalhostsucceedcook server --host: all succeedcook server --host ::1: only::1andlocalhostsucceedcook server --host <IPv4 LAN address>: only IPv4 LAN address succeedscook server --host <IPv6 LAN address>: only IPv6 LAN address succeeds