Struct axum_server::Server [−][src]
pub struct Server { /* fields omitted */ }
Expand description
Configurable HTTP server, supporting HTTP/1.1 and HTTP2.
Server
can conveniently be turned into a TlsServer
with related methods.
See main page for HTTP example. See axum_server::tls
module for HTTPS example.
Implementations
pub fn bind<A, I>(self, addr: A) -> Self where
A: ToSocketAddrs<Iter = I> + Send + 'static,
I: Iterator<Item = SocketAddr> + 'static,
pub fn bind<A, I>(self, addr: A) -> Self where
A: ToSocketAddrs<Iter = I> + Send + 'static,
I: Iterator<Item = SocketAddr> + 'static,
Bind to a single address or multiple addresses.
pub fn bind_rustls<A, I>(self, addr: A) -> TlsServer where
A: ToSocketAddrs<Iter = I> + Send + 'static,
I: Iterator<Item = SocketAddr> + 'static,
This is supported on crate feature tls-rustls
only.
pub fn bind_rustls<A, I>(self, addr: A) -> TlsServer where
A: ToSocketAddrs<Iter = I> + Send + 'static,
I: Iterator<Item = SocketAddr> + 'static,
tls-rustls
only.Bind to a single address or multiple addresses. Using tls protocol on streams.
Certificate and private key must be set before or after calling this.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Provide a loaded TlsLoader
.
This will overwrite any previously set private key and certificate(s) with its own ones.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Provide ServerConfig
containing private key and certificate(s).
When this value is set, other tls configurations are ignored.
Successive calls will overwrite last value.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Set private key in PEM format.
Successive calls will overwrite last private key.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Set certificate(s) in PEM format.
Successive calls will overwrite last certificate.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Set private key from file in PEM format.
Successive calls will overwrite last private key.
This is supported on crate feature tls-rustls
only.
tls-rustls
only.Set certificate(s) from file in PEM format.
Successive calls will overwrite last certificate.
Provide a Handle
.
Successive calls will overwrite last Handle
.
Serve provided cloneable service on all binded addresses.
If accepting connection fails in any one of binded addresses, listening in all binded addresses will be stopped and then an error will be returned.
pub async fn serve_and_record<S, B>(self, service: S) -> Result<()> where
S: Service<Request<Body>, Response = Response<B>> + Send + Sync + Clone + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>>,
S::Future: Send,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn Error + Send + Sync>>,
This is supported on crate feature record
only.
pub async fn serve_and_record<S, B>(self, service: S) -> Result<()> where
S: Service<Request<Body>, Response = Response<B>> + Send + Sync + Clone + 'static,
S::Error: Into<Box<dyn Error + Send + Sync>>,
S::Future: Send,
B: Body + Send + 'static,
B::Data: Send,
B::Error: Into<Box<dyn Error + Send + Sync>>,
record
only.Serve provided cloneable service on all binded addresses.
Record sent and received bytes for each connection independently. Sent and
received bytes through a connection can be accessed through Request
extensions.
See axum_server::record
module for examples.
If accepting connection fails in any one of binded addresses, listening in all binded addresses will be stopped and then an error will be returned.