Skip to content
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

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

Closed
jonhoo opened this issue Jul 22, 2023 · 4 comments
Closed

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

jonhoo opened this issue Jul 22, 2023 · 4 comments
Labels
C-feature Category: feature. This is adding a new feature.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Jul 22, 2023

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

@jonhoo jonhoo added the C-feature Category: feature. This is adding a new feature. label Jul 22, 2023
@tomkarw
Copy link
Contributor

tomkarw commented Jul 26, 2023

The implementation is simple, the question is whether adding a new public API to v0.14.x is worth it during v1.0 effort.

@jonhoo
Copy link
Contributor Author

jonhoo commented Aug 20, 2023

I think this can now be closed since #3278 landed?

@tomkarw
Copy link
Contributor

tomkarw commented Aug 20, 2023

I think Sean is waiting untill the patch with the change is realeased? Not sure what the process is.

@seanmonstar
Copy link
Member

Oh, nope, it just doesn't auto-close become it was merged to a different branch, not master. We can close! (And I'll schedule a 0.14 release this week, cleaning through inbox.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature. This is adding a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants