When asking Iron to listen on localhost:0, the kernel assigns an unused port number, and getaddrinfo resolves localhost to 127.0.0.1. The actual address can be displayed via format!("{}", listening.socket) where listening is an instance of the type returned by Iron::http and friends.
Example output from racerd
The first line is my own logging, and the second line is from this crate.
racerd listening at 127.0.0.1:54663
GET http://localhost:0/ping -> 200 OK (0.086167 ms)
Discussion
I'm not familiar with all members of the Request type, but it seems that Iron would need to pass in either the address or a reference to the listening server in order to access this information.
When asking Iron to listen on
localhost:0, the kernel assigns an unused port number, and getaddrinfo resolves localhost to127.0.0.1. The actual address can be displayed viaformat!("{}", listening.socket)wherelisteningis an instance of the type returned byIron::httpand friends.Example output from racerd
The first line is my own logging, and the second line is from this crate.
Discussion
I'm not familiar with all members of the
Requesttype, but it seems that Iron would need to pass in either the address or a reference to the listening server in order to access this information.