-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Is your feature request related to a problem? Please describe.
I'd like to be able to get the local address that Server::bind
(which returns a Builder<AddrIncoming, E>
) bound to before calling Builder::serve
so that I can pass the local address to the service I'm about to pass into serve
.
Describe the solution you'd like
Add fn local_addr(&self) -> SocketAddr
to impl Builder<AddrIncoming, E>
.
Describe alternatives you've considered
Provide a way to access the full AddrIncoming
via Builder
, but that feels probably excessive.
Additional context
This is particularly relevant when the address passed to bind uses port 0
. This comes up for me occasionally in tests where I want the test service to be aware of its own port number (to, e.g., echo back in a HTML body), which means I need to know the port before I can construct the service to pass to Builder::serve
to get a Server
(which does provide local_addr
).