ListenerHTTP1/ListenerHTTP: allow choosing the bind address (always 0.0.0.0 today) #11
Labels
No labels
claude:blocked
claude:done
claude:failed
claude:in-progress
claude:ready
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Catcrafts/Crafter.Network#11
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
ListenerHTTP1andListenerAsyncHTTP1take a port and nothing else. Every constructor ends in the port-onlyListenerTCPoverload:and that overload binds every IPv4 interface (
0.0.0.0). A consumer has no way to ask for127.0.0.1.For an HTTP/1.1 listener that is the wrong address more often than not. The usual deployment is a backend behind a reverse proxy that terminates TLS, and such a backend is only correct while nothing but the proxy can reach it:
X-Forwarded-Forentry), which anyone who connects directly can write themselves;catcrafts.netis this case: Caddy in front,ListenerHTTP1behind. The server was written to listen on loopback, says so in its own startup line, and cannot make it true.ss -ltnshows0.0.0.0:<port>, and the only thing that keeps the port private is a host firewall rule, which is one layer where there should be two.The lower layers already take an address. Only the HTTP listeners cannot pass one down:
Proposal
Overloads with the address first, as
ListenerTCPandListenerQUIChave them, forwarding to those:the same four on
ListenerAsyncHTTP1, and for symmetry onListenerHTTP/ListenerAsyncHTTP, which sit onListenerQUICand have the same gap.Same rules as the layers below, so there is one behaviour to learn: a numeric IPv4 or IPv6 address, a name such as
localhostrefused, and port0letting the kernel pick. That last one needs aPort()on the HTTP listeners to be useful (ListenerTCPandListenerQUIChave it), which would also let tests stop choosing ports by hand.Fully backwards compatible: the port-only constructors keep binding what they bind today.
Smaller things in the same place
ListenerHTTP1do not say what they bind.ListenerTCP's comment does ("Every IPv4 interface (0.0.0.0) atport"), and so doesAGENTS.consumer.mdforListenerTCP; the HTTP listener's header comment and its consumer section are where someone deploying behind a proxy would look, and neither mentions it. One sentence there would have caught this.What catcrafts.net does with it
plus a suite that asserts the socket does not answer on a non-loopback address, so the startup line cannot drift from the truth again.