Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport): Make server builder more consitient #901

Merged
merged 2 commits into from Feb 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions tonic/src/transport/server/mod.rs
Expand Up @@ -159,6 +159,7 @@ impl<L> Server<L> {
/// Configure TLS for this server.
#[cfg(feature = "tls")]
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
#[must_use]
pub fn tls_config(self, tls_config: ServerTlsConfig) -> Result<Self, Error> {
Ok(Server {
tls: Some(tls_config.tls_acceptor().map_err(Error::from_source)?),
Expand All @@ -176,6 +177,7 @@ impl<L> Server<L> {
/// # let builder = Server::builder();
/// builder.concurrency_limit_per_connection(32);
/// ```
#[must_use]
pub fn concurrency_limit_per_connection(self, limit: usize) -> Self {
Server {
concurrency_limit: Some(limit),
Expand All @@ -191,12 +193,15 @@ impl<L> Server<L> {
/// # use tonic::transport::Server;
/// # use tower_service::Service;
/// # use std::time::Duration;
/// # let mut builder = Server::builder();
/// # let builder = Server::builder();
/// builder.timeout(Duration::from_secs(30));
/// ```
pub fn timeout(&mut self, timeout: Duration) -> &mut Self {
self.timeout = Some(timeout);
self
#[must_use]
pub fn timeout(self, timeout: Duration) -> Self {
Server {
timeout: Some(timeout),
..self
}
}

/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
Expand All @@ -205,6 +210,7 @@ impl<L> Server<L> {
/// Default is 65,535
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
#[must_use]
pub fn initial_stream_window_size(self, sz: impl Into<Option<u32>>) -> Self {
Server {
init_stream_window_size: sz.into(),
Expand All @@ -215,6 +221,7 @@ impl<L> Server<L> {
/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
#[must_use]
pub fn initial_connection_window_size(self, sz: impl Into<Option<u32>>) -> Self {
Server {
init_connection_window_size: sz.into(),
Expand All @@ -228,6 +235,7 @@ impl<L> Server<L> {
/// Default is no limit (`None`).
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_MAX_CONCURRENT_STREAMS
#[must_use]
pub fn max_concurrent_streams(self, max: impl Into<Option<u32>>) -> Self {
Server {
max_concurrent_streams: max.into(),
Expand All @@ -244,6 +252,7 @@ impl<L> Server<L> {
///
/// Default is no HTTP2 keepalive (`None`)
///
#[must_use]
pub fn http2_keepalive_interval(self, http2_keepalive_interval: Option<Duration>) -> Self {
Server {
http2_keepalive_interval,
Expand All @@ -258,6 +267,7 @@ impl<L> Server<L> {
///
/// Default is 20 seconds.
///
#[must_use]
pub fn http2_keepalive_timeout(self, http2_keepalive_timeout: Option<Duration>) -> Self {
Server {
http2_keepalive_timeout,
Expand All @@ -273,6 +283,7 @@ impl<L> Server<L> {
///
/// Default is no keepalive (`None`)
///
#[must_use]
pub fn tcp_keepalive(self, tcp_keepalive: Option<Duration>) -> Self {
Server {
tcp_keepalive,
Expand All @@ -281,6 +292,7 @@ impl<L> Server<L> {
}

/// Set the value of `TCP_NODELAY` option for accepted connections. Enabled by default.
#[must_use]
pub fn tcp_nodelay(self, enabled: bool) -> Self {
Server {
tcp_nodelay: enabled,
Expand All @@ -293,6 +305,7 @@ impl<L> Server<L> {
/// Passing `None` will do nothing.
///
/// If not set, will default from underlying transport.
#[must_use]
pub fn max_frame_size(self, frame_size: impl Into<Option<u32>>) -> Self {
Server {
max_frame_size: frame_size.into(),
Expand All @@ -308,6 +321,7 @@ impl<L> Server<L> {
/// return confusing (but correct) protocol errors.
///
/// Default is `false`.
#[must_use]
pub fn accept_http1(self, accept_http1: bool) -> Self {
Server {
accept_http1,
Expand All @@ -316,6 +330,7 @@ impl<L> Server<L> {
}

/// Intercept inbound headers and add a [`tracing::Span`] to each response future.
#[must_use]
pub fn trace_fn<F>(self, f: F) -> Self
where
F: Fn(&http::Request<()>) -> tracing::Span + Send + Sync + 'static,
Expand Down