Skip to content

Builder<AddrIncoming, E> does not expose SocketAddr getter #3272

@jonhoo

Description

@jonhoo

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-featureCategory: feature. This is adding a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions