1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
*
* Copyright 2025 gRPC authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
//! Batteries included server and client.
//!
//! This module provides a set of batteries included, fully featured and
//! fast set of HTTP/2 server and client's. These components each provide a
//! `rustls` tls backend when the respective feature flag is enabled, and
//! provides builders to configure transport behavior.
//!
//! # Features
//!
//! - TLS support via [rustls].
//! - Load balancing
//! - Timeouts
//! - Concurrency Limits
//! - Rate limiting
//!
//! # Examples
//!
//! ## Client
//!
//! ```no_run
//! # #[cfg(feature = "rustls")]
//! # use tonic::transport::{Channel, Certificate, ClientTlsConfig};
//! # use std::time::Duration;
//! # use tonic::client::GrpcService;;
//! # use http::Request;
//! # #[cfg(feature = "rustls")]
//! # async fn do_thing() -> Result<(), Box<dyn std::error::Error>> {
//! let cert = std::fs::read_to_string("ca.pem")?;
//!
//! let mut channel = Channel::from_static("https://example.com")
//! .tls_config(ClientTlsConfig::new()
//! .ca_certificate(Certificate::from_pem(&cert))
//! .domain_name("example.com".to_string()))?
//! .timeout(Duration::from_secs(5))
//! .rate_limit(5, Duration::from_secs(1))
//! .concurrency_limit(256)
//! .connect()
//! .await?;
//!
//! channel.call(Request::new(tonic::body::empty_body())).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Server
//!
//! ```no_run
//! # use std::convert::Infallible;
//! # #[cfg(feature = "rustls")]
//! # use tonic::transport::{Server, Identity, ServerTlsConfig};
//! # use tonic::body::Body;
//! # use tower::Service;
//! # #[cfg(feature = "rustls")]
//! # async fn do_thing() -> Result<(), Box<dyn std::error::Error>> {
//! # #[derive(Clone)]
//! # pub struct Svc;
//! # impl Service<hyper::Request<Body>> for Svc {
//! # type Response = hyper::Response<Body>;
//! # type Error = Infallible;
//! # type Future = std::future::Ready<Result<Self::Response, Self::Error>>;
//! # fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
//! # Ok(()).into()
//! # }
//! # fn call(&mut self, _req: hyper::Request<Body>) -> Self::Future {
//! # unimplemented!()
//! # }
//! # }
//! # impl tonic::server::NamedService for Svc {
//! # const NAME: &'static str = "some_svc";
//! # }
//! # let my_svc = Svc;
//! let cert = std::fs::read_to_string("server.pem")?;
//! let key = std::fs::read_to_string("server.key")?;
//!
//! let addr = "[::1]:50051".parse()?;
//!
//! Server::builder()
//! .tls_config(ServerTlsConfig::new()
//! .identity(Identity::from_pem(&cert, &key)))?
//! .concurrency_limit_per_connection(256)
//! .add_service(my_svc)
//! .serve(addr)
//! .await?;
//!
//! # Ok(())
//! # }
//! ```
//!
//! [rustls]: https://docs.rs/rustls/0.16.0/rustls/
pub use ;
pub use Error;
pub use Server;
pub use Certificate;
pub use ;
pub use CertificateDer;
pub use ClientTlsConfig;
pub use ServerTlsConfig;
pub use Identity;