hyperium / hyper

An HTTP library for Rust
https://hyper.rs
MIT License
14.42k stars 1.59k forks source link

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

Closed jonhoo closed 1 year ago

jonhoo commented 1 year ago

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

tomkarw commented 1 year ago

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 commented 1 year ago

I think this can now be closed since https://github.com/hyperium/hyper/pull/3278 landed?

tomkarw commented 1 year ago

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

seanmonstar commented 1 year ago

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