pub struct Server<F> {
pipeline: bool,
filter: F,
}
Expand description
A Warp Server ready to filter requests.
Fields§
§pipeline: bool
§filter: F
Implementations§
source§impl<F> Server<F>
impl<F> Server<F>
sourcepub async fn run(self, addr: impl Into<SocketAddr>)
pub async fn run(self, addr: impl Into<SocketAddr>)
Run this Server
forever on the current thread.
§Panics
Panics if we are unable to bind to the provided address.
sourcepub async fn run_incoming<I>(self, incoming: I)
pub async fn run_incoming<I>(self, incoming: I)
Run this Server
forever on the current thread with a specific stream
of incoming connections.
This can be used for Unix Domain Sockets, or TLS, etc.
async fn run_incoming2<I>(self, incoming: I)
sourcepub fn bind(
self,
addr: impl Into<SocketAddr> + 'static,
) -> impl Future<Output = ()> + 'static
pub fn bind( self, addr: impl Into<SocketAddr> + 'static, ) -> impl Future<Output = ()> + 'static
Bind to a socket address, returning a Future
that can be
executed on the current runtime.
§Panics
Panics if we are unable to bind to the provided address.
sourcepub async fn try_bind(self, addr: impl Into<SocketAddr>)
pub async fn try_bind(self, addr: impl Into<SocketAddr>)
Bind to a socket address, returning a Future
that can be
executed on any runtime.
In case we are unable to bind to the specified address, resolves to an error and logs the reason.
sourcepub fn bind_ephemeral(
self,
addr: impl Into<SocketAddr>,
) -> (SocketAddr, impl Future<Output = ()> + 'static)
pub fn bind_ephemeral( self, addr: impl Into<SocketAddr>, ) -> (SocketAddr, impl Future<Output = ()> + 'static)
Bind to a possibly ephemeral socket address.
Returns the bound address and a Future
that can be executed on
the current runtime.
§Panics
Panics if we are unable to bind to the provided address.
sourcepub fn try_bind_ephemeral(
self,
addr: impl Into<SocketAddr>,
) -> Result<(SocketAddr, impl Future<Output = ()> + 'static), Error>
pub fn try_bind_ephemeral( self, addr: impl Into<SocketAddr>, ) -> Result<(SocketAddr, impl Future<Output = ()> + 'static), Error>
Tried to bind a possibly ephemeral socket address.
Returns a Result
which fails in case we are unable to bind with the
underlying error.
Returns the bound address and a Future
that can be executed on
the current runtime.
sourcepub fn bind_with_graceful_shutdown(
self,
addr: impl Into<SocketAddr> + 'static,
signal: impl Future<Output = ()> + Send + 'static,
) -> (SocketAddr, impl Future<Output = ()> + 'static)
pub fn bind_with_graceful_shutdown( self, addr: impl Into<SocketAddr> + 'static, signal: impl Future<Output = ()> + Send + 'static, ) -> (SocketAddr, impl Future<Output = ()> + 'static)
Create a server with graceful shutdown signal.
When the signal completes, the server will start the graceful shutdown process.
Returns the bound address and a Future
that can be executed on
the current runtime.
§Example
use warp::Filter;
use futures_util::future::TryFutureExt;
use tokio::sync::oneshot;
let routes = warp::any()
.map(|| "Hello, World!");
let (tx, rx) = oneshot::channel();
let (addr, server) = warp::serve(routes)
.bind_with_graceful_shutdown(([127, 0, 0, 1], 3030), async {
rx.await.ok();
});
// Spawn the server into a runtime
tokio::task::spawn(server);
// Later, start the shutdown...
let _ = tx.send(());
§Panics
Panics if we are unable to bind to the provided address.
sourcepub fn try_bind_with_graceful_shutdown(
self,
addr: impl Into<SocketAddr> + 'static,
signal: impl Future<Output = ()> + Send + 'static,
) -> Result<(SocketAddr, impl Future<Output = ()> + 'static), Error>
pub fn try_bind_with_graceful_shutdown( self, addr: impl Into<SocketAddr> + 'static, signal: impl Future<Output = ()> + Send + 'static, ) -> Result<(SocketAddr, impl Future<Output = ()> + 'static), Error>
Create a server with graceful shutdown signal.
When the signal completes, the server will start the graceful shutdown process.
sourcepub fn serve_incoming<I>(self, incoming: I) -> impl Future<Output = ()>
pub fn serve_incoming<I>(self, incoming: I) -> impl Future<Output = ()>
Setup this Server
with a specific stream of incoming connections.
This can be used for Unix Domain Sockets, or TLS, etc.
Returns a Future
that can be executed on the current runtime.
sourcepub fn serve_incoming_with_graceful_shutdown<I>(
self,
incoming: I,
signal: impl Future<Output = ()> + Send + 'static,
) -> impl Future<Output = ()>
pub fn serve_incoming_with_graceful_shutdown<I>( self, incoming: I, signal: impl Future<Output = ()> + Send + 'static, ) -> impl Future<Output = ()>
Setup this Server
with a specific stream of incoming connections and a
signal to initiate graceful shutdown.
This can be used for Unix Domain Sockets, or TLS, etc.
When the signal completes, the server will start the graceful shutdown process.
Returns a Future
that can be executed on the current runtime.