pub async fn serve<U: Upstream>(
listener: TcpListener,
service: ProxyService<U>,
) -> Result<()>Expand description
Serve service on listener: cleartext HTTP/1.1 and HTTP/2 on the same
port, so REST clients and native gRPC clients share it. It runs until the
future is dropped, which closes every connection; serve_with_shutdown
stops gracefully, and serve_with adds TLS and a connection limit.
§Errors
None so far: a failed accept is logged and retried, as a full file descriptor table recovers when connections close.
§Examples
use structured_proxy::ProxyServer;
let grpc = tonic::service::Routes::default();
let service = ProxyServer::from_yaml_str("service:\n name: demo\n")?.service(grpc)?;
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await?;
structured_proxy::serve(listener, service).await?;