pub struct Server { /* private fields */ }server only.Expand description
ConnectRPC server built on hyper.
Implementations§
Source§impl Server
impl Server
Sourcepub fn from_service(service: ConnectRpcService) -> Self
pub fn from_service(service: ConnectRpcService) -> Self
Create a new server from an existing ConnectRpcService.
Sourcepub fn with_tls(self, config: Arc<ServerConfig>) -> Self
Available on crate feature server-tls only.
pub fn with_tls(self, config: Arc<ServerConfig>) -> Self
server-tls only.Enable TLS with the given rustls server configuration.
The configuration controls all TLS behavior including certificate
selection, client authentication, and protocol versions. For dynamic
certificate rotation, use a rustls::server::ResolvesServerCert
implementation in the config.
§Example
use std::sync::Arc;
let tls_config = Arc::new(rustls::ServerConfig::builder()
.with_no_client_auth()
.with_single_cert(certs, key)?);
Server::new(router)
.with_tls(tls_config)
.serve(addr).await?;Sourcepub fn tls_handshake_timeout(self, timeout: Duration) -> Self
Available on crate feature server-tls only.
pub fn tls_handshake_timeout(self, timeout: Duration) -> Self
server-tls only.Set the TLS handshake timeout.
Defaults to DEFAULT_TLS_HANDSHAKE_TIMEOUT (10 seconds). A client
that connects via TCP but does not complete the TLS handshake within
this duration is disconnected.
Sourcepub async fn serve(
self,
addr: SocketAddr,
) -> Result<(), Box<dyn Error + Send + Sync>>
pub async fn serve( self, addr: SocketAddr, ) -> Result<(), Box<dyn Error + Send + Sync>>
Bind and serve on the given address.
This runs forever until the process is killed. For graceful shutdown,
use Server::bind + BoundServer::serve_with_graceful_shutdown.
Sourcepub fn from_listener(listener: TcpListener) -> BoundServer
pub fn from_listener(listener: TcpListener) -> BoundServer
Bind to the given address and return a BoundServer.
Accepts anything implementing tokio::net::ToSocketAddrs:
"127.0.0.1:8080"— IPv4 loopback (safest default for dev)"[::1]:8080"— IPv6 loopback"0.0.0.0:8080"— all IPv4 interfaces (only for trusted networks)"[::]:8080"— all IPv6 interfaces (on Linux, also accepts IPv4 via IPv4-mapped addresses by default)"localhost:8080"— resolves via DNS/hosts (may yield v4, v6, or both)
Wrap a pre-bound TcpListener.
Use this instead of Server::bind when you need to configure
socket options before binding — e.g. IPV6_V6ONLY=false for
dual-stack listening, SO_REUSEPORT for multi-process accept,
or binding to a listener inherited from a parent process.
Sourcepub async fn bind(
addr: impl ToSocketAddrs,
) -> Result<BoundServer, Box<dyn Error + Send + Sync>>
pub async fn bind( addr: impl ToSocketAddrs, ) -> Result<BoundServer, Box<dyn Error + Send + Sync>>
When multiple addresses are returned (e.g. localhost resolving to
both ::1 and 127.0.0.1), the first that successfully binds is used.