You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[*] I have looked for existing issues (including closed) about this
Feature Request
I would like to get the socket address of Serve and WithGracefulShutdown.
Motivation
I am the maintainer of Axum Test, and the initial motivation behind this is to help with testing servers that have been gracefully shutdown. The way Axum Test works is by having a TestServer, and one passes in a Router or a IntoMakeService, and the TestServer then sets that up to be served.
This is relevant, as it means a developer cannot call Serve::with_graceful_shutdown before passing their application into a TestServer.
I can extend my code to allow that. However I need to know what address the Serve is running on, in order to then make requests to it. Ideally I'd like to be able to just get it from Serve directly.
Proposal
I'd propose to add the methods Serve::local_addr and WithGracefulShutdown::local_addr. This is pretty simple to do, and the code would be something like:
I would be happy to make a PR for this myself if there is interest.
Alternatives
Could offer a means to expose the TcpListener.
Another alternative could be to move the with_graceful_shutdown to be attached earlier, before calling serve. This would make it separate to what the service is listening to, and could also solve my issue (although this would be a large and breaking API change).
The text was updated successfully, but these errors were encountered:
Adds methods for exposing the address the Axum servers are bound to.
* add `Serve::local_addr`
* add `WithGracefulShutdown::local_addr`
Implements tokio-rs#2879
Feature Request
I would like to get the socket address of
Serve
andWithGracefulShutdown
.Motivation
I am the maintainer of Axum Test, and the initial motivation behind this is to help with testing servers that have been gracefully shutdown. The way Axum Test works is by having a
TestServer
, and one passes in aRouter
or aIntoMakeService
, and theTestServer
then sets that up to be served.This is relevant, as it means a developer cannot call
Serve::with_graceful_shutdown
before passing their application into aTestServer
.I can extend my code to allow that. However I need to know what address the
Serve
is running on, in order to then make requests to it. Ideally I'd like to be able to just get it fromServe
directly.Proposal
I'd propose to add the methods
Serve::local_addr
andWithGracefulShutdown::local_addr
. This is pretty simple to do, and the code would be something like:I would be happy to make a PR for this myself if there is interest.
Alternatives
Could offer a means to expose the
TcpListener
.Another alternative could be to move the
with_graceful_shutdown
to be attached earlier, before callingserve
. This would make it separate to what the service is listening to, and could also solve my issue (although this would be a large and breaking API change).The text was updated successfully, but these errors were encountered: